You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The inline class feature specification does not specify the treatment of super in the bodies of instance members.
An expression whose type is an inline class can be the receiver of member invocations where the member is declared in any of its superinterfaces, direct or indirect, as long as the given declaration isn't redeclared by some other declaration with the same name in a "nearer" superinterface. Conflicts are resolved by redeclaring a member with the same name (but it is not required that the redeclaration is a correct override). For example:
inline classA1 {
finalint i;
A1(this.i);
voidfoo() {}
intget bar => i +1;
}
inline classA2 {
finalint i;
A2(this.i);
voidfoo() {}
intget baz => i -1;
}
inline classBimplementsA1, A2 {
finalint i;
B(this.i);
Stringfoo() =>'B.foo'; // Redeclare, required due to ambiguity.
}
voidmain() {
var b =B(10);
print('${b.foo()}: ${b.bar * b.baz}'); // Prints 'B.foo: 99'.
}
Hence, an inline class cannot treat super in a way that resembles the treatment in a regular class:
super would need to be disambiguated in cases like super.foo() in B. Some proposals were put forward about using constructs like A1.super.foo() to disambiguate the invocation, but those proposals did not receive much support. Moreover, it may be misleading to use super to call A1.foo from B (from the body of B.foo or anywhere else), because it is simply a different member than B.foo (we never choose between A1.foo and B.foo based on dispatch at run time).
If we do come up with a useful treatment of super in an inline class then we will be able to do whatever we want, if it is made an error for now.
I tend to think that we should simply make all occurrences of super in an inline class a compile-time error at this time.
@dart-lang/language-team, WDYT?
The text was updated successfully, but these errors were encountered:
If we allow extends as in #2967, so the inline class doesn't have to declare an instance variable for the representation type itself, we may want to allow calling the extended class's members using super.
Indeed! That's what I suggested to do with a similar design:
extensionclassC1extendsC {
// `super` is an expression with type `C` that denotes the representation object.
}
The point is that the different keywords extension class allow us to optimize for the case where the declaration should add a bunch of sticky extension methods to a given class. If we do get a form of declaration where super is used in that manner then it will probably be even more confusing if super is used by inline classes for some other purpose.
Uh oh!
There was an error while loading. Please reload this page.
Thanks for @sgrekhov for noticing this.
The inline class feature specification does not specify the treatment of
super
in the bodies of instance members.An expression whose type is an inline class can be the receiver of member invocations where the member is declared in any of its superinterfaces, direct or indirect, as long as the given declaration isn't redeclared by some other declaration with the same name in a "nearer" superinterface. Conflicts are resolved by redeclaring a member with the same name (but it is not required that the redeclaration is a correct override). For example:
Hence, an inline class cannot treat
super
in a way that resembles the treatment in a regular class:super
would need to be disambiguated in cases likesuper.foo()
inB
. Some proposals were put forward about using constructs likeA1.super.foo()
to disambiguate the invocation, but those proposals did not receive much support. Moreover, it may be misleading to usesuper
to callA1.foo
fromB
(from the body ofB.foo
or anywhere else), because it is simply a different member thanB.foo
(we never choose betweenA1.foo
andB.foo
based on dispatch at run time).If we do come up with a useful treatment of
super
in an inline class then we will be able to do whatever we want, if it is made an error for now.I tend to think that we should simply make all occurrences of
super
in an inline class a compile-time error at this time.@dart-lang/language-team, WDYT?
The text was updated successfully, but these errors were encountered: