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

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

Issue 12052084: Issue 8027. Disallow cyclic mixins. (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 f85ccd538e2eb04a2a9491ffdf567437bc38777e..9a4cbf1e295641360ee8a560d6cf512e42f8d93b 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());
}
+ checkMixinObjectIsSupertype(cls.getMixins());
checkMixinNoConstructors(cls.getMixins());
checkMixinNoSuperInvocations(cls.getMixins());
return classElement;
@@ -490,6 +491,7 @@ public class Resolver {
}
// check mixins
+ checkMixinObjectIsSupertype(cls.getMixins());
checkMixinNoConstructors(cls.getMixins());
checkMixinNoSuperInvocations(cls.getMixins());
@@ -517,7 +519,27 @@ public class Resolver {
}
/**
- * Checks that the types of the given mixin type node don't have super invocations.
+ * Checks that the types of the given mixin type nodes se subtypes of Object.
+ */
+ private void checkMixinObjectIsSupertype(List<DartTypeNode> mixins) {
+ for (DartTypeNode mixNode : mixins) {
+ if (mixNode.getType() instanceof InterfaceType) {
+ InterfaceType mixType = (InterfaceType) mixNode.getType();
+ ClassElement mixElement = mixType.getElement();
+ if (!mixElement.getMixins().isEmpty()) {
+ topLevelContext.onError(mixNode, ResolverErrorCode.CANNOT_MIXIN_CLASS_WITH_MIXINS);
+ continue;
+ }
+ if (!Objects.equal(mixElement.getSupertype(), typeProvider.getObjectType())) {
+ topLevelContext.onError(mixNode, ResolverErrorCode.ONLY_OBJECT_MIXIN_SUPERCLASS);
+ continue;
+ }
+ }
+ }
+ }
+
+ /**
+ * Checks that the types of the given mixin type nodes don't have super invocations.
*/
private void checkMixinNoSuperInvocations(List<DartTypeNode> mixins) {
for (DartTypeNode mixNode : mixins) {
« 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