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
As part of simplifying augmentations (#4256), we're planning to remove support for augmented and the ability for an augmentation to wrap existing code and call it. So this wouldn't be allowed:
The difference is that method mixed in by the augmentation ends up before the introductory method instead of after it, which is why the introductory method has to call super.foo() for it to be reached.
You can think of a class body as sort of like an in-place mixin definition and application:
classCwithM1, M2, M3 {
foo() {
print('foo');
}
}
// Is pretty much the same as:classCwithM1, M2, M3, _ClassBody {}
mixin_ClassBody {
foo() {
print('foo');
}
}
That suggests a natural extension where we loosen the restriction that the "class body mixin" has to be last in the mixin chain. Syntactically, it could be maybe:
The mixins (including the { ... } class body one) are then applied in that order with the mixins in the trailing with clause applied after the class body itself. If we had that, then the above augmentation example could look like:
classC {
foo() {
print('introductory');
}
}
augmentclassC {} with_M// ^^^^^^^ After class body now.mixin_M {
foo() {
super.foo();
print('augmented');
}
}
main() {
C().foo(); // Prints "introductory" then "augmented".
}
Now the augmentation's mixed in methods correctly come after the methods in the introductory declaration. The augmented method now gets to call super.foo() to reach the introductory declaration instead of the order being reversed.
Does this feature carry its weight? Is it a good idea? Not sure. But I figured it was worth writing up.
The text was updated successfully, but these errors were encountered:
I like it.
I should, it allows overriding as the "augmented" feature, like #4308, but using mixins like #4203 (comment)
In the latter comment it is suggested that you can have multiple body blocks too, which just avoids declaring a one-use mixin with a hard-to-express on type (which would probably require an extra interface as well, to inject before the mixin application.).
The example above has this problem. The _M mixin does a super.foo invocation, but doesn't have an on clause.
As part of simplifying augmentations (#4256), we're planning to remove support for
augmented
and the ability for an augmentation to wrap existing code and call it. So this wouldn't be allowed:Even without
augmented
, an augmentation could almost accomplish the same thing by applying a mixin:The difference is that method mixed in by the augmentation ends up before the introductory method instead of after it, which is why the introductory method has to call
super.foo()
for it to be reached.You can think of a class body as sort of like an in-place mixin definition and application:
That suggests a natural extension where we loosen the restriction that the "class body mixin" has to be last in the mixin chain. Syntactically, it could be maybe:
The mixins (including the
{ ... }
class body one) are then applied in that order with the mixins in the trailingwith
clause applied after the class body itself. If we had that, then the above augmentation example could look like:Now the augmentation's mixed in methods correctly come after the methods in the introductory declaration. The augmented method now gets to call
super.foo()
to reach the introductory declaration instead of the order being reversed.Does this feature carry its weight? Is it a good idea? Not sure. But I figured it was worth writing up.
The text was updated successfully, but these errors were encountered: