Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(52)

Unified Diff: sdk/lib/_internal/compiler/implementation/resolution/members.dart

Issue 88153003: Add synthetic type variables to unnamed mixin applications. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updated cf. comments. Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: sdk/lib/_internal/compiler/implementation/resolution/members.dart
diff --git a/sdk/lib/_internal/compiler/implementation/resolution/members.dart b/sdk/lib/_internal/compiler/implementation/resolution/members.dart
index 3e04dc9fb3c24d8f3853847fbddfd11ebb96ef65..6cae6f715413f21ce03d2def37135670c81f6675 100644
--- a/sdk/lib/_internal/compiler/implementation/resolution/members.dart
+++ b/sdk/lib/_internal/compiler/implementation/resolution/members.dart
@@ -3832,8 +3832,8 @@ class ClassResolverVisitor extends TypeDefinitionVisitor {
DartType supertype = resolveSupertype(element, superMixin.superclass);
Link<Node> link = superMixin.mixins.nodes;
while (!link.isEmpty) {
- supertype = applyMixin(
- supertype, checkMixinType(link.head), link.head);
+ supertype = applyMixin(supertype,
+ checkMixinType(link.head), link.head);
link = link.tail;
}
element.supertype = supertype;
@@ -3929,16 +3929,45 @@ class ClassResolverVisitor extends TypeDefinitionVisitor {
DartType applyMixin(DartType supertype, DartType mixinType, Node node) {
String superName = supertype.name;
String mixinName = mixinType.name;
- ClassElement mixinApplication = new MixinApplicationElementX(
+ MixinApplicationElementX mixinApplication = new MixinApplicationElementX(
"${superName}+${mixinName}",
element.getCompilationUnit(),
compiler.getNextFreeClassId(),
node,
Modifiers.EMPTY); // TODO(kasperl): Should this be abstract?
+ // Create synthetic type variables for the mixin application.
+ LinkBuilder<DartType> typeVariablesBuilder = new LinkBuilder<DartType>();
+ element.typeVariables.forEach((TypeVariableType type) {
+ TypeVariableElementX typeVariableElement = new TypeVariableElementX(
+ type.name, mixinApplication, type.element.parseNode(compiler));
+ TypeVariableType typeVariable = new TypeVariableType(typeVariableElement);
+ typeVariablesBuilder.addLast(typeVariable);
+ });
+ Link<DartType> typeVariables = typeVariablesBuilder.toLink();
+ // Setup bounds on the synthetic type variables.
+ Link<DartType> link = typeVariables;
+ element.typeVariables.forEach((TypeVariableType type) {
+ TypeVariableType typeVariable = link.head;
+ TypeVariableElement typeVariableElement = typeVariable.element;
+ typeVariableElement.type = typeVariable;
+ typeVariableElement.bound =
+ type.element.bound.subst(typeVariables, element.typeVariables);
+ link = link.tail;
+ });
+ // Setup this and raw type for the mixin application.
+ mixinApplication.computeThisAndRawType(compiler, typeVariables);
+ // Substitute in synthetic type variables in super and mixin types.
+ supertype = supertype.subst(typeVariables, element.typeVariables);
+ mixinType = mixinType.subst(typeVariables, element.typeVariables);
+
doApplyMixinTo(mixinApplication, supertype, mixinType);
mixinApplication.resolutionState = STATE_DONE;
mixinApplication.supertypeLoadState = STATE_DONE;
- return mixinApplication.computeType(compiler);
+ // Replace the synthetic type variables by the original type variables in
+ // the returned type (which should be the type actually extended).
+ InterfaceType mixinThisType = mixinApplication.computeType(compiler);
+ return mixinThisType.subst(element.typeVariables,
+ mixinThisType.typeArguments);
}
bool isDefaultConstructor(FunctionElement constructor) {
@@ -4135,7 +4164,7 @@ class ClassResolverVisitor extends TypeDefinitionVisitor {
cls.allSupertypesAndSelf =
new OrderedTypeSet.singleton(cls.computeType(compiler));
}
- }
+ }
/**
* Adds [type] and all supertypes of [type] to [allSupertypes] while

Powered by Google App Engine
This is Rietveld 408576698