-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
Hello!
Before the recent InvalidType changes, when a code-generator encountered an invalid type, they generated "dynamic". But now, the same generator will generate InvalidType
, which is not a valid symbol.
This breaks apps that use possibly two code-generators.
As an example, consider an app which uses two code-generators:
- one code-generator adds a copyWith to classes
- one generator emits a
CodeGeneratedClass
Then, a user would write:
@CopyWith()
class Example with _$Example { // mixin used to add the copyWith method
Example(this.value);
List<CodeGeneratedClass> value;
}
In that case, before the recent InvalidType changes, the generated copyWith would be:
mixin _$Example on Example {
Example copyWith({
// "value" is typed as dynamic because at the time of generation,
// the class "CodeGeneratedClass" does not exist. Therefore dynamic used to be returned.
List<dynamic> value,
}) => ...;
}
That behavior was reasonable. It wasn't perfectly typed, but the generated code worked.
So someone could reasonably write:
void main() {
Example example = Example([]);
example = example.coyWith(value: [CodeGeneratedClass()]);
}
But with the recent changes, the generated copyWith is now instead:
mixin _$Example on Example {
Example copyWith({
List<InvalidType> value,
}) => ...;
}
The problem is that this code is no longer valid. The InvalidType type does not exist, and even if it did, CodeGeneratedClass
would not be assignable to it.
As such, the application does not compile anymore