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

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

Issue 10540029: Adds a warning if the + opearator is used with two strings. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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/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 719a9b20808cc5f957f8dbd84b0c1854d81e7b12..b2bf34ca799263e83b68b599a3ba85874053c6de 100644
--- a/compiler/java/com/google/dart/compiler/type/TypeAnalyzer.java
+++ b/compiler/java/com/google/dart/compiler/type/TypeAnalyzer.java
@@ -347,7 +347,10 @@ public class TypeAnalyzer implements DartCompilationPhase {
return rhs;
}
- case ASSIGN_ADD:
+ case ASSIGN_ADD: {
+ checkStringConcatPlus(lhsNode);
+ checkStringConcatPlus(rhsNode);
+ }
case ASSIGN_SUB:
case ASSIGN_MUL:
case ASSIGN_DIV:
@@ -405,7 +408,10 @@ public class TypeAnalyzer implements DartCompilationPhase {
}
}
- case ADD:
+ case ADD: {
+ checkStringConcatPlus(lhsNode);
+ checkStringConcatPlus(rhsNode);
+ }
case SUB:
case MUL:
case DIV:
@@ -441,6 +447,22 @@ public class TypeAnalyzer implements DartCompilationPhase {
}
}
+ private void checkStringConcatPlus(DartExpression node) {
+ if (node != null) {
+ Type type = null;
+ if (node.getElement() != null) {
+ type = node.getElement().getType();
+ } else if (node.getType() != null) {
+ type = node.getType();
+ }
+ if (type != null) {
+ if (type.equals(stringType)) {
+ onError(node, TypeErrorCode.PLUS_CANNOT_BE_USED_FOR_STRING_CONCAT);
+ }
+ }
+ }
+ }
+
@Override
public Type visitVariableStatement(DartVariableStatement node) {
Type type = typeOf(node.getTypeNode());

Powered by Google App Engine
This is Rietveld 408576698