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

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

Issue 26745004: Implement type variable 'more specific than' and 'subtype'. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 2 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
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 8aa3df06ee066c587da1ad3bedd84c64030a11cf..107e6c8e6d4b2978f7242383f6c87757385091f8 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
@@ -934,6 +934,7 @@ public class ErrorVerifier extends RecursiveASTVisitor<Void> {
checkForBuiltInIdentifierAsName(
node.getName(),
CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE_PARAMETER_NAME);
+ checkForTypeParameterSupertypeOfItsBound(node);
return super.visitTypeParameter(node);
}
@@ -4584,6 +4585,32 @@ public class ErrorVerifier extends RecursiveASTVisitor<Void> {
}
/**
+ * This checks that if the passed type parameter is a supertype of its bound.
+ *
+ * @param node the type parameter to evaluate
+ * @return {@code true} if and only if an error code is generated on the passed node
+ * @see StaticTypeWarningCode#TYPE_PARAMETER_SUPERTYPE_OF_ITS_BOUND
+ */
+ private boolean checkForTypeParameterSupertypeOfItsBound(TypeParameter node) {
+ TypeParameterElement element = node.getElement();
+ // prepare bound
+ Type bound = element.getBound();
+ if (bound == null) {
+ return false;
+ }
+ // OK, type parameter is not supertype of its bound
+ if (!bound.isMoreSpecificThan(element.getType())) {
+ return false;
+ }
+ // report problem
+ errorReporter.reportError(
+ StaticTypeWarningCode.TYPE_PARAMETER_SUPERTYPE_OF_ITS_BOUND,
+ node,
+ element.getDisplayName());
+ return true;
+ }
+
+ /**
* This checks that if the passed generative constructor has neither an explicit super constructor
* invocation nor a redirecting constructor invocation, that the superclass has a default
* generative constructor.

Powered by Google App Engine
This is Rietveld 408576698