Index: compiler/java/com/google/dart/compiler/resolver/Resolver.java |
diff --git a/compiler/java/com/google/dart/compiler/resolver/Resolver.java b/compiler/java/com/google/dart/compiler/resolver/Resolver.java |
index f40cb666b9aa9fa87c9f44224695d4e92c79cd51..ee9e72fa56046c024461d4b247c0a92fc8631374 100644 |
--- a/compiler/java/com/google/dart/compiler/resolver/Resolver.java |
+++ b/compiler/java/com/google/dart/compiler/resolver/Resolver.java |
@@ -372,6 +372,7 @@ public class Resolver { |
} |
onError(errorTarget, ResolverErrorCode.CYCLIC_CLASS, e.getElement().getName()); |
} |
+ checkMixinNoConstructors(cls.getMixins()); |
return classElement; |
} |
@@ -487,12 +488,32 @@ public class Resolver { |
} |
} |
+ // check that mixin types don't have constructors |
+ checkMixinNoConstructors(cls.getMixins()); |
+ |
context = previousContext; |
currentHolder = previousHolder; |
enclosingElement = previousEnclosingElement; |
return classElement; |
} |
+ /** |
+ * Checks that the types of the given mixin type node don't have explicit constructors. |
+ */ |
+ private void checkMixinNoConstructors(List<DartTypeNode> mixins) { |
+ for (DartTypeNode mixNode : mixins) { |
+ if (mixNode.getType() instanceof InterfaceType) { |
+ InterfaceType mixType = (InterfaceType) mixNode.getType(); |
+ for (ConstructorElement constructor : mixType.getElement().getConstructors()) { |
+ if (!constructor.getModifiers().isFactory()) { |
+ topLevelContext.onError(mixNode, ResolverErrorCode.CANNOT_MIXIN_CLASS_WITH_CONSTRUCTOR); |
+ break; |
+ } |
+ } |
+ } |
+ } |
+ } |
+ |
private void constVerifyMembers(Iterable<? extends Element> members, ClassElement originalClass, |
ClassElement currentClass) { |
for (Element element : members) { |
@@ -2220,9 +2241,9 @@ public class Resolver { |
private ConstructorElement checkIsConstructor(DartNewExpression node, Element element) { |
if (!ElementKind.of(element).equals(ElementKind.CONSTRUCTOR)) { |
- ResolverErrorCode errorCode = node.isConst() |
+ ErrorCode errorCode = node.isConst() |
? ResolverErrorCode.NEW_EXPRESSION_NOT_CONST_CONSTRUCTOR |
- : ResolverErrorCode.NEW_EXPRESSION_NOT_CONSTRUCTOR; |
+ : TypeErrorCode.NEW_EXPRESSION_NOT_CONSTRUCTOR; |
onError(ASTNodes.getConstructorNameNode(node), errorCode); |
return null; |
} |