-
Notifications
You must be signed in to change notification settings - Fork 202
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Do we allow a late final variable to obtain an initializing expression from an augmenting declaration? #3735
Comments
Interesting - yes it does sound like a unique property of this kind of augmentation, which is not desirable. I think it would be reasonable to say that an augmentation is not allowed to introduce an initializer for a late final variable. This can't be expressed through the macro API unfortunately, but we can just rely on the general purpose error (to be specified in the augmentation library spec). |
From the general rule of augmentations not changing signatures, an augmentation should not be allowed to add an initializer to a |
Looks like the dicision has been made. It is a compile-time error to add an initializing expression to a |
You should be able to do You should probably also be able to do |
I'll conclude that it is an error for a late final instance variable without an initializing expression to be augmented with a declaration that has an initializing expression. |
Closing: This error has been included in the feature specification as of #3800. |
Consider the following program:
I can't find a rule to say that this is a compile-time error in the feature specification.
However, I do think it should be an error: The augmenting declaration (presumably) adds an initializing expression to the declaration of
x
inlib.dart
, but at the same time it eliminates the implicitly induced setter (which is needed because we must be able to initialize the variable, but it has a restricted semantics because we are not allowed to mutate the value, that is, it will throw on every non-first invocation).I think it is a unique property of this kind of augmentation that it eliminates a setter which would otherwise exist (I don't think we have any other augmentations that will eliminate any entity).
(I think we are just about to decide that library augmentations should just be part files, but that shouldn't change anything.)
@dart-lang/language-team, WDYT?
The text was updated successfully, but these errors were encountered: