Cannot name a field override
because of @override
annotation
#992
Labels
bug
Something isn't working
override
because of @override
annotation
#992
Describe the bug
Naming a field
override
causes the@override
annotation to resolve to the local field instead of to@override
fromdart:core
. This also, rather confusingly, displays errors on the first field to be defined, rather than on the field namedoverride
.See also: dart-lang/source_gen#688
To Reproduce
See the code snippet above.
Expected behavior
Well, ideally, this would "just work". However, because the field is shadowing the import from
dart:core
and - as @jakemac53 rightly pointed out in the linked issue above - part files cannot declare imports, there might need to be some kind of workaround, or it can just error out and say that a field cannot be named import.Proposed solutions
I've tried none of the following solutions, but off the top of my head, these could be some ways to solve the issue?
override
that wouldn't be used by an end user that "extends@override
fromdart:core
and place it in thefreezed_annotations
package. (e.g.,freezed_override_annotation
) and use that annotation instead?override
and refuse to generate the code based on that - that's also the approach anyone trying to name a field asoverride
has had to take anyway - this would just make it less confusing as to the cause of the issue.dart:core
with some alias that is then used if that additional import is detected? (I think this would also mean it could be a private alias - e.g.,_core
which would certainly alleviate any naming conflicts).The text was updated successfully, but these errors were encountered: