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
Augmenting declarations do not introduce a binding into any scope, right? #3739
Comments
#3738 seems like it is also related here? If we are using a pure lexical scope, does an augmenting declaration introduce something into the lexical scope or not? |
In general though yes, augmenting declarations do not introduce a new declaration, and you are supposed to be able to introduce a declaration and augment it in the same file. |
Agree. An augmenting declaration doesn't have to introduce a name. About #3738, that's a good question. int method = 42;
augment class C {
augment void method() {} // Introduces *name* into lexical scope.
void bar() {
method(); // Calls this.method();
}
} the For the outer If you have multiple declarations with the same name in the same scope, then they only introduce the name once. int foo = 42;
class C {
void foo() {}
augment void foo() {}
augment void foo() {}
void bar() {
foo(); // Resolves to an instance member, so becomes `this.foo()`.
}
} |
Closing: At this time every proposed model for augmentations imply that the augmentation declaration does not introduce the name of the declaration into the enclosing scope (or any other scope). So the answer is "Correct, they don't". |
Thanks to @mit-mit for bringing up this issue! Consider the following program:
This program is accepted by the analyzer (8dabf6a7524689a0c89e241bdb4b18daf2b479e3), but the CFE (same commit) rejects it as follows:
I haven't found explicit language about the effect of augmenting declarations on the enclosing scope. That is, does an augmenting declaration introduce a name into the scope just like a regular declaration? I'd assume the answer is no.
In particular, the feature specification contains several examples where a declaration and one or more augmenting declarations with the same name occur in the same scope, e.g., the declarations named
trace
in this section. These examples are concerned with declarations in the library scope, there are no examples involving class member declarations.However, if we do adopt the rule that augmenting declarations refer to an existing declaration by name, and they don't introduce any bindings of that name into any scopes, then we'd allow the original declaration and any number of augmenting declarations to coexist in the same scope, at any level where they can otherwise occur.
@munificent, @jakemac53, WDYT?
The text was updated successfully, but these errors were encountered: