Skip to content
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

[augmentations] No error if there is metadata named augmented in augmentation scope #59774

Open
sgrekhov opened this issue Dec 20, 2024 · 2 comments
Labels
analyzer-spec Issues with the analyzer's implementation of the language spec area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. feature-augmentations Implementation of the augmentations feature P2 A bug or feature request we're likely to work on

Comments

@sgrekhov
Copy link
Contributor

In an augmentation scope augmented is a reserved world and can be used for calling introductory declaration only. Any other use of this word is a compile-time error. But there is no expected error in the analyzer below:

class augmented {
  const augmented();
}
class C {}

augment class C {
  @augmented()  // There should be an error here but there isn't
  void foo() {}
}

Appropriate co19 test, for example, https://github.com/dart-lang/co19/blob/master/LanguageFeatures/Augmentation-libraries/augmented_expression_A03_t33.dart

@sgrekhov sgrekhov added area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. feature-augmentations Implementation of the augmentations feature labels Dec 20, 2024
@srawlins srawlins added the type-enhancement A request for a change that isn't a bug label Dec 27, 2024
@keertip keertip added the P2 A bug or feature request we're likely to work on label Jan 2, 2025
@lrhn
Copy link
Member

lrhn commented Jan 2, 2025

I've been arguing that augmented should only be reserved in places where it can actually mean "invoke the augmented declaration", so only where there can be an expression (function bodies, initializer lists, default value expressions and variable initializer expressions).

I don't remember what was decided about that, if anything.

@eernstg
Copy link
Member

eernstg commented Jan 6, 2025

The language team decided at the meeting Oct 30 2024 that the currently specified treatment should not change. This implies that augmented inside a declaration marked as augment cannot be used in any other way than as a reference to the augmented declaration (that is, an invocation of the augmented method or getter, or as an evaluation of the augmented initializing expression). In particular:

Inside an expression in an augmenting member declaration, the identifier augmented can be used to refer to the augmented function, getter, or setter body, or variable initializer. This is a contextual reserved word within augment declarations

A compile-time error occurs if a declaration with the basename augmented occurs in a location where any enclosing declaration is augmenting. This error is applicable to all such declarations, e.g., local functions, local variables, parameters, and type parameters.

Consider a non-augmenting member declaration Dm that occurs inside an augmenting type declaration Dt. A compile-time error occurs if the identifier augmented occurs in Dm.

For example, inside augment class C we could have a declaration like void f() {...augmented()...}. This is an error because the outer augment forces the meaning of augmented to be about augmentation in the entire scope, but the method declaration is introductory and hence there is no earlier declaration to augment.

So the error at @augmented() which was mentioned in the original posting should indeed be reported.

@eernstg eernstg added analyzer-spec Issues with the analyzer's implementation of the language spec and removed type-enhancement A request for a change that isn't a bug labels Jan 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-spec Issues with the analyzer's implementation of the language spec area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. feature-augmentations Implementation of the augmentations feature P2 A bug or feature request we're likely to work on
Projects
None yet
Development

No branches or pull requests

5 participants