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

Unified Diff: compiler/java/com/google/dart/compiler/resolver/Resolver.java

Issue 12048003: Issue 8025. Disallow mixing in classes that have constructors. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 11 months 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
« no previous file with comments | « no previous file | compiler/java/com/google/dart/compiler/resolver/ResolverErrorCode.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
}
« no previous file with comments | « no previous file | compiler/java/com/google/dart/compiler/resolver/ResolverErrorCode.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698