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

Unified Diff: editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/verifier/ErrorVerifier.java

Issue 18293017: Report MIXIN_TYPEDEF_CYCLE. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Report TYPE_ALIAS_CANNOT_REFERENCE_ITSELF instead Created 7 years, 5 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 | editor/tools/plugins/com.google.dart.engine_test/src/com/google/dart/engine/resolver/CompileTimeErrorCodeTest.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/verifier/ErrorVerifier.java
diff --git a/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/verifier/ErrorVerifier.java b/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/verifier/ErrorVerifier.java
index ab40ce800bce046395c54340d1d231b9bae1bc71..f8a1374224b7c8b4f6d80f2fc2623d7a07cb17c2 100644
--- a/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/verifier/ErrorVerifier.java
+++ b/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/verifier/ErrorVerifier.java
@@ -457,6 +457,7 @@ public class ErrorVerifier extends RecursiveASTVisitor<Void> {
try {
enclosingClass = node.getElement();
checkForRecursiveInterfaceInheritance(node.getElement(), new ArrayList<ClassElement>());
+ checkForTypeAliasCannotReferenceItself_mixin(node);
} finally {
enclosingClass = outerClassElement;
}
@@ -608,7 +609,7 @@ public class ErrorVerifier extends RecursiveASTVisitor<Void> {
node.getName(),
CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPEDEF_NAME);
checkForDefaultValueInFunctionTypeAlias(node);
- checkForTypeAliasCannotReferenceItself(node);
+ checkForTypeAliasCannotReferenceItself_function(node);
return super.visitFunctionTypeAlias(node);
}
@@ -4229,7 +4230,7 @@ public class ErrorVerifier extends RecursiveASTVisitor<Void> {
* @return {@code true} if and only if an error code is generated on the passed node
* @see CompileTimeErrorCode#TYPE_ALIAS_CANNOT_REFERENCE_ITSELF
*/
- private boolean checkForTypeAliasCannotReferenceItself(FunctionTypeAlias node) {
+ private boolean checkForTypeAliasCannotReferenceItself_function(FunctionTypeAlias node) {
FunctionTypeAliasElement element = node.getElement();
if (!hasFunctionTypeAliasSelfReference(element)) {
return false;
@@ -4239,6 +4240,21 @@ public class ErrorVerifier extends RecursiveASTVisitor<Void> {
}
/**
+ * This verifies that the given class type alias does not reference itself.
+ *
+ * @return {@code true} if and only if an error code is generated on the passed node
+ * @see CompileTimeErrorCode#TYPE_ALIAS_CANNOT_REFERENCE_ITSELF
+ */
+ private boolean checkForTypeAliasCannotReferenceItself_mixin(ClassTypeAlias node) {
+ ClassElement element = node.getElement();
+ if (!hasClassTypeAliasSelfReference(element, new HashSet<ClassElement>())) {
+ return false;
+ }
+ errorReporter.reportError(CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF, node);
+ return true;
+ }
+
+ /**
* This verifies that the type arguments in the passed type name are all within their bounds.
*
* @param node the {@link TypeName} to evaluate
@@ -4585,6 +4601,28 @@ public class ErrorVerifier extends RecursiveASTVisitor<Void> {
}
/**
+ * @return <code>true</code> if given {@link ClassElement} has direct or indirect reference to
+ * itself using only other typedef {@link ClassElement}s.
+ */
+ private boolean hasClassTypeAliasSelfReference(ClassElement element,
+ HashSet<ClassElement> seenMixins) {
+ if (seenMixins.contains(element)) {
+ return true;
+ }
+ seenMixins.add(element);
+ for (InterfaceType mixin : element.getMixins()) {
+ ClassElement mixinElement = mixin.getElement();
+ if (!mixinElement.isTypedef()) {
+ continue;
+ }
+ if (hasClassTypeAliasSelfReference(mixinElement, seenMixins)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
* Checks if "target" is referenced by "current".
*/
private boolean hasFunctionTypeAliasReference(Set<FunctionTypeAliasElement> visited,
« no previous file with comments | « no previous file | editor/tools/plugins/com.google.dart.engine_test/src/com/google/dart/engine/resolver/CompileTimeErrorCodeTest.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698