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

Unified Diff: compiler/java/com/google/dart/compiler/type/TypeAnalyzer.java

Issue 9355006: Issue 1475. Report warning for non-unique Map literal keys. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 10 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/type/TypeAnalyzer.java
diff --git a/compiler/java/com/google/dart/compiler/type/TypeAnalyzer.java b/compiler/java/com/google/dart/compiler/type/TypeAnalyzer.java
index 50b57754640065acf336184be7f882206cb1b31e..53c8aa859550326f6c074b9db8e2b9f8fd92cf84 100644
--- a/compiler/java/com/google/dart/compiler/type/TypeAnalyzer.java
+++ b/compiler/java/com/google/dart/compiler/type/TypeAnalyzer.java
@@ -1113,8 +1113,8 @@ public class TypeAnalyzer implements DartCompilationPhase {
// specified <V> where V is the type of the value.
checkAssignable(node, type, defaultLiteralMapType);
- Type valueType = type.getArguments().get(1);
// Check the map literal entries against the return type.
+ Type valueType = type.getArguments().get(1);
for (DartMapLiteralEntry literalEntry : node.getEntries()) {
boolean result = checkAssignable(literalEntry, typeOf(literalEntry), valueType);
if (developerModeChecks == true && result == false) {
@@ -1122,6 +1122,20 @@ public class TypeAnalyzer implements DartCompilationPhase {
valueType.toString());
}
}
+
+ // Check that each key literal is unique.
+ Set<String> keyValues = Sets.newHashSet();
+ for (DartMapLiteralEntry literalEntry : node.getEntries()) {
+ if (literalEntry.getKey() instanceof DartStringLiteral) {
+ DartStringLiteral keyLiteral = (DartStringLiteral) literalEntry.getKey();
+ String keyValue = keyLiteral.getValue();
+ if (keyValues.contains(keyValue)) {
+ typeError(keyLiteral, TypeErrorCode.MAP_LITERAL_KEY_UNIQUE);
+ }
+ keyValues.add(keyValue);
+ }
+ }
+
return type;
}

Powered by Google App Engine
This is Rietveld 408576698