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

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

Issue 10546168: Issue 3540. Better error message for string concatenation (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 c7815476b0e5446c4e45510b222881d4cb364309..86ce98df8a11f75e7795d67e51f6d0658a8e8573 100644
--- a/compiler/java/com/google/dart/compiler/type/TypeAnalyzer.java
+++ b/compiler/java/com/google/dart/compiler/type/TypeAnalyzer.java
@@ -357,8 +357,7 @@ public class TypeAnalyzer implements DartCompilationPhase {
}
case ASSIGN_ADD: {
- checkStringConcatPlus(lhsNode);
- checkStringConcatPlus(rhsNode);
+ checkStringConcatPlus(node, lhs);
}
case ASSIGN_SUB:
case ASSIGN_MUL:
@@ -418,8 +417,7 @@ public class TypeAnalyzer implements DartCompilationPhase {
}
case ADD: {
- checkStringConcatPlus(lhsNode);
- checkStringConcatPlus(rhsNode);
+ checkStringConcatPlus(node, lhs);
}
case SUB:
case MUL:
@@ -469,19 +467,12 @@ 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);
- }
- }
+ private void checkStringConcatPlus(DartBinaryExpression binary, Type lhs) {
+ if (Objects.equal(lhs, stringType)) {
+ Token operator = binary.getOperator();
+ SourceInfo errorTarget = new SourceInfo(binary.getSourceInfo().getSource(),
+ binary.getOperatorOffset(), operator.getSyntax().length());
+ onError(errorTarget, TypeErrorCode.PLUS_CANNOT_BE_USED_FOR_STRING_CONCAT, operator);
}
}

Powered by Google App Engine
This is Rietveld 408576698