language
language copied to clipboard
Allow `augmented` as the name of a named argument or as a member name?
The augmentation feature specification makes it an error to use augmented
as an identifier expression anywhere inside an augmenting declaration.
In https://github.com/dart-lang/language/issues/4009, it is discussed whether we should allow augmented
to be used as an identifier expression in some cases (in particular, inside a non-augmenting member declaration which is in turn inside an augmenting type-introducing declaration, e.g., augment class C { void foo() { ... augmented ...} }
).
We do have the opportunity to allow augmented to be used in several other ways that aren't identifier expressions:
- As the name of a named parameter in an invocation, e.g.,
foo(augmented: true)
. - As the name of a named parameter in a declaration, e.g.,
void foo({augmented = 0})
. - As the name of a record getter, e.g.,
(1, augmented: 'Certainly!')
. - As a selector, e.g.,
e.augmented
. This covers cascades as well, e.g.,e..augmented
. - As the second part of the name in an instance creation expression, e.g.,
C.augmented(5)
. - As the second part of the name of a constructor declaration, e.g.,
augment class C { int i; C.augmented(this.i); }
. - As the name of a member declaration, e.g.,
augment class C { void augmented() {}}
.
In all cases there is no way the given occurrence of augmented
could be an application of the feature that allows us to call the augmented declaration or evaluate the initializing expression of the augmented declaration. It is evident from the syntax that we have one of these cases (in other words, we don't have to look up anything in order to detect that we have one of these cases).
In other words, we could allow these usages anywhere inside an augmenting declaration.
The argument in favor of doing this would be that it is possible and may be convenient (and the workaround which is needed otherwise includes inconvenient things like top-level wrapper functions that will call the function that takes the named argument, etc, if there even is a workaround).
The argument against doing this is that it is likely to be a source of confusion that augmented
can be anything other than an invocation of the augmented entity inside an augmenting declaration.
If we decide in #4009 that augmented
as an identifier expression in augment class C { void foo() { ... augmented ...} }
is simply a reference to a declaration named augmented
which is in scope then I believe we should also allow the usages mentioned above.
It is possible that the specification already implies that we can use augmented
in some of these cases (many of them are certainly errors currently, but there could be loopholes). However, it will probably be useful to discuss it in more detail in any case.
@dart-lang/language-team, WDYT?