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

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

Issue 10544068: Issue 3307. Report error when built-in identifier used as type annotation (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Status file changes after new co19 Created 8 years, 6 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: compiler/java/com/google/dart/compiler/resolver/ResolutionContext.java
diff --git a/compiler/java/com/google/dart/compiler/resolver/ResolutionContext.java b/compiler/java/com/google/dart/compiler/resolver/ResolutionContext.java
index 31b8e82c403f11c8f3c8e07fd614db90c9911989..9efd3dacc772808896c28a43a95102632fe9459b 100644
--- a/compiler/java/com/google/dart/compiler/resolver/ResolutionContext.java
+++ b/compiler/java/com/google/dart/compiler/resolver/ResolutionContext.java
@@ -23,10 +23,12 @@ import com.google.dart.compiler.ast.LibraryUnit;
import com.google.dart.compiler.ast.Modifiers;
import com.google.dart.compiler.common.HasSourceInfo;
import com.google.dart.compiler.common.SourceInfo;
+import com.google.dart.compiler.parser.DartParser;
import com.google.dart.compiler.type.InterfaceType;
import com.google.dart.compiler.type.Type;
import com.google.dart.compiler.type.TypeKind;
import com.google.dart.compiler.type.TypeVariable;
+import com.google.dart.compiler.type.Types;
import java.util.Arrays;
import java.util.List;
@@ -214,6 +216,15 @@ public class ResolutionContext implements ResolutionErrorListener {
Type resolveType(DartNode diagnosticNode, DartNode identifier, List<DartTypeNode> typeArguments,
boolean isStatic, boolean isFactory, ErrorCode errorCode) {
+ // Built-in identifier can not be used as a type annotation.
+ if (identifier instanceof DartIdentifier) {
+ String name = ((DartIdentifier) identifier).getName();
+ if (DartParser.PSEUDO_KEYWORDS_SET.contains(name)) {
+ onError(identifier, ResolverErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE, name);
+ return Types.newDynamicType();
+ }
+ }
+ // OK, valid name for type.
Element element = resolveName(identifier);
ElementKind elementKind = ElementKind.of(element);
switch (elementKind) {

Powered by Google App Engine
This is Rietveld 408576698