freezed icon indicating copy to clipboard operation
freezed copied to clipboard

When the common type of a shared property is not accessible within the library, attempt again with an ancestor type

Open CodingSoot opened this issue 2 years ago • 0 comments

The feature introduced in #740 is great.

However, sometimes the common type might not be accessible in the freezed file, which causes errors.

For example :

// In a library which only exports A, B and C and Common1 but doesn't export Common2
class Common1 {}

class Common2 extends Common1 {}

class A extends Common2{}

class B extends Common2{}
// In a different library that imports the library above
@freezed
class MyUnion with _$MyUnion {
  const factory MyUnion.first(A param) = _First;

  const factory MyUnion.second(B param) = _Second;
}

The generated getter is Common2 get param => throw _privateConstructorUsedError;, with an error Undefined class 'Common2'.

What should instead happen is skip the common type Common2, and pick instead Common1 which is higher in the class hierarchy but is accessible.

CodingSoot avatar Feb 05 '23 18:02 CodingSoot