Skip to content

Commit 5b3cadc

Browse files
nshahancommit-bot@chromium.org
authored andcommitted
[ddc] Add getter to accompany setter from mixin
When a mixin introduces a forwarding stub setter in the class hierarchy there also needs to be the accompanying getter in the same class if a getter is present further up the class hierarchy. This is because the setter is represented as a property with only a setter and the lack of a getter will not cause a lookup further up the prototype chain. Fixes: dart-lang/sdk#46867 Change-Id: I8e41eb9d2569f0819200a82367ab7c723a1011cd Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/209854 Commit-Queue: Nicholas Shahan <[email protected]> Reviewed-by: Mark Zhou <[email protected]>
1 parent a899525 commit 5b3cadc

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

pkg/dev_compiler/lib/src/kernel/compiler.dart

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,13 +1127,29 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
11271127
var mixinName =
11281128
getLocalClassName(superclass) + '_' + getLocalClassName(mixinClass);
11291129
var mixinId = _emitTemporaryId(mixinName + '\$');
1130-
// Collect all forwarding stubs from anonymous mixins classes. These will
1131-
// contain covariant parameter checks that need to be applied.
1132-
var forwardingMethodStubs = [
1130+
// Collect all forwarding stub setters from anonymous mixins classes.
1131+
// These will contain covariant parameter checks that need to be applied.
1132+
var savedClassProperties = _classProperties;
1133+
_classProperties =
1134+
ClassPropertyModel.build(_types, _extensionTypes, _virtualFields, m);
1135+
1136+
var forwardingSetters = {
11331137
for (var procedure in m.procedures)
11341138
if (procedure.isForwardingStub && !procedure.isAbstract)
1135-
_emitMethodDeclaration(procedure)
1136-
];
1139+
procedure.name.text: procedure
1140+
};
1141+
1142+
var forwardingMethodStubs = <js_ast.Method>[];
1143+
for (var s in forwardingSetters.values) {
1144+
forwardingMethodStubs.add(_emitMethodDeclaration(s));
1145+
// If there are getters matching the setters somewhere above in the
1146+
// class hierarchy we must also generate a forwarding getter due to the
1147+
// representation used in the compiled JavaScript.
1148+
var getterWrapper = _emitSuperAccessorWrapper(s, {}, forwardingSetters);
1149+
if (getterWrapper != null) forwardingMethodStubs.add(getterWrapper);
1150+
}
1151+
1152+
_classProperties = savedClassProperties;
11371153

11381154
// Bind the mixin class to a name to workaround a V8 bug with es6 classes
11391155
// and anonymous function names.

0 commit comments

Comments
 (0)