freezed icon indicating copy to clipboard operation
freezed copied to clipboard

fix deprecations from analyzer: 4.4.0

Open SunlightBro opened this issue 2 years ago • 1 comments

analyzer: 4.4.0 changelog

  • Deprecated DartType.element, check for InterfaceType, TypeParameterType, and then ask the element.

No breaking changes in analyzer: 4.5.0 that effect freezed.

SunlightBro avatar Aug 10 '22 07:08 SunlightBro

~~When running tests on my device source_gen_test fails for me ...~~

00:04 +50 -1: loading test/source_gen_test.dart [E]                                                                                                                                                                                    
  Failed to load "test/source_gen_test.dart": Failed to decode data using encoding 'utf-8', path = 'test/.DS_Store'
  dart:io                                                     _File.readAsStringSync

🙈 rm test/.DS_Store and all is fine.

SunlightBro avatar Aug 10 '22 07:08 SunlightBro

With analyzer: 4.6.0 changelog

Added DartType.element2, so that InterfaceType.element2 overrides it.

My approach of using type-promotion is no longer strictly necessary and simply replacing .element with .element2 would be enough.

Except FreezedGenerator's _hasCustomToString and _hasCustomEquals would still have to

@@ -648,8 +648,8 @@ Read here: https://github.com/rrousselGit/freezed/blob/master/packages/freezed/C
    for (final type in [
      element,
      ...element.allSupertypes
-         .map((e) => e.element) // element is of type ClassElement
          .where((e) => !e.isDartCoreObject) // Filter out DartCoreObjects before mapping
+         .map((e) => e.element2) // element2 is of type InterfaceElement
    ]) {
      for (final method in type.methods) {
        if (method.name == 'toString') {

Let me know if the PR in this form is still relevant or if I should close it.

SunlightBro avatar Aug 14 '22 15:08 SunlightBro

Nice! Thanks for the your work :)

rrousselGit avatar Aug 14 '22 21:08 rrousselGit