Description
Surely it would violate some invariants that we can otherwise rely on if augmented()
is allowed to be executed in the initializer list of a non-redirecting, or in the redirection of a redirecting generative constructor. (In short: general code gets to see an object which is not initialized.)
However, I can't find an explicit indication in the feature specification that there must be such an error. Here is an example. Currently (ac9b6d1672255d2233ed612eb9c94921dca3cd3a), the analyzer does not report any errors.
class A {
dynamic x;
A() {
print('Running introductory!');
}
augment A(): x = augmented();
}
class B {
B(Object? o);
B.named(): this(42);
augment B.named(): this(augmented());
}
I think we must specify a compile-time error for both of these situations, because the initializer list / redirection does not have access to this
, but the body of an augmented generative constructor can access this
.
Of course, we could also allow both of them, and consider augmented
to be a regular identifier in both situations, potentially resolving to a static, top-level, or imported declaration. We'd then have an error if augmented()
in that context resolves to an instance member of the enclosing class/enum/extension-type, because the initializer list / redirection does not have access to this
.
@dart-lang/language-team, WDYT?