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

Unified Diff: editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/resolver/TypeResolverVisitor.java

Issue 14855015: Report StaticWarningCode.NEW_WITH_NON_TYPE and CompileTimeErrorCode.CONST_WITH_NON_TYPE (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fixes for review comments Created 7 years, 7 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/resolver/TypeResolverVisitor.java
diff --git a/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/resolver/TypeResolverVisitor.java b/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/resolver/TypeResolverVisitor.java
index 8bc7792f0999151e1e7e638d6fa587a00ff98f81..74d771a469f0258e50ebcaf8dc1abe72e6d05338 100644
--- a/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/resolver/TypeResolverVisitor.java
+++ b/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/resolver/TypeResolverVisitor.java
@@ -417,22 +417,40 @@ public class TypeResolverVisitor extends ScopedVisitor {
}
}
}
- if (element == null) {
+ // check element
Brian Wilkerson 2013/05/10 16:13:29 I think this will work, but it seems (without tryi
+ boolean elementValid = !(element instanceof MultiplyDefinedElement);
+ if (elementValid && !(element instanceof ClassElement)
+ && isTypeNameInInstanceCreationExpression(node)) {
+ SimpleIdentifier typeNameSimple = getTypeSimpleIdentifier(typeName);
+ InstanceCreationExpression creation = (InstanceCreationExpression) node.getParent().getParent();
+ if (creation.isConst()) {
+ if (element == null) {
+ reportError(CompileTimeErrorCode.UNDEFINED_CLASS, typeNameSimple, typeName);
+ } else {
+ reportError(CompileTimeErrorCode.CONST_WITH_NON_TYPE, typeNameSimple, typeName);
+ }
+ elementValid = false;
+ } else {
+ if (element != null) {
+ reportError(StaticWarningCode.NEW_WITH_NON_TYPE, typeNameSimple, typeName);
+ elementValid = false;
+ }
+ }
+ }
+ if (elementValid && element == null) {
// We couldn't resolve the type name.
// TODO(jwren) Consider moving the check for CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE
// from the ErrorVerifier, so that we don't have two errors on a built in identifier being
// used as a class name. See CompileTimeErrorCodeTest.test_builtInIdentifierAsType().
- Identifier simpleIdentifier;
- if (typeName instanceof SimpleIdentifier) {
- simpleIdentifier = typeName;
- } else {
- simpleIdentifier = ((PrefixedIdentifier) typeName).getPrefix();
- }
- if (simpleIdentifier.getName().equals("boolean")) {
- reportError(StaticWarningCode.UNDEFINED_CLASS_BOOLEAN, simpleIdentifier);
+ SimpleIdentifier typeNameSimple = getTypeSimpleIdentifier(typeName);
+ if (typeNameSimple.getName().equals("boolean")) {
+ reportError(StaticWarningCode.UNDEFINED_CLASS_BOOLEAN, typeNameSimple);
} else {
- reportError(StaticWarningCode.UNDEFINED_CLASS, simpleIdentifier, simpleIdentifier.getName());
+ reportError(StaticWarningCode.UNDEFINED_CLASS, typeNameSimple, typeNameSimple.getName());
}
+ elementValid = false;
+ }
+ if (!elementValid) {
setElement(typeName, dynamicType.getElement());
typeName.setStaticType(dynamicType);
node.setType(dynamicType);
@@ -676,6 +694,37 @@ public class TypeResolverVisitor extends ScopedVisitor {
}
/**
+ * Returns the simple identifier of the given (may be qualified) type name.
+ *
+ * @param typeName the (may be qualified) qualified type name
+ * @return the simple identifier of the given (may be qualified) type name.
+ */
+ private SimpleIdentifier getTypeSimpleIdentifier(Identifier typeName) {
+ if (typeName instanceof SimpleIdentifier) {
+ return (SimpleIdentifier) typeName;
+ } else {
+ return ((PrefixedIdentifier) typeName).getIdentifier();
+ }
+ }
+
+ /**
+ * Checks if the given type name is used as the type in the instance creation expression.
+ *
+ * @param typeName the type name to analyzer
+ * @return {@code true} if the given type name is used as the type in the instance creation
+ * expression
+ */
+ private boolean isTypeNameInInstanceCreationExpression(TypeName typeName) {
+ ASTNode parent = typeName.getParent();
+ if (parent instanceof ConstructorName
+ && parent.getParent() instanceof InstanceCreationExpression) {
+ ConstructorName constructorName = (ConstructorName) parent;
+ return constructorName != null && constructorName.getType() == typeName;
+ }
+ return false;
+ }
+
+ /**
* Record that the static type of the given node is the given type.
*
* @param expression the node whose type is to be recorded

Powered by Google App Engine
This is Rietveld 408576698