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

Unified Diff: compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerTest.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/javatests/com/google/dart/compiler/type/TypeAnalyzerTest.java
diff --git a/compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerTest.java b/compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerTest.java
index 7e3ae899f5571b0dec645b9cf1f38284aaa97986..12e268bde6d8ed1d3cbed8ee7055defa1ed10df9 100644
--- a/compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerTest.java
+++ b/compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerTest.java
@@ -108,8 +108,10 @@ public class TypeAnalyzerTest extends TypeAnalyzerTestCase {
analyzeIn(cls, expression, 0);
expression = String.format("s = o %s o", op.getSyntax());
analyzeIn(cls, expression, 1);
- expression = String.format("o %s s", op.getSyntax());
- analyzeIn(cls, expression, 1);
+ if (!op.equals(Token.ADD)) {
+ expression = String.format("o %s s", op.getSyntax());
+ analyzeIn(cls, expression, 1);
+ }
expression = String.format("o %s i", op.getSyntax());
analyzeIn(cls, expression, 1);
}
@@ -160,18 +162,20 @@ public class TypeAnalyzerTest extends TypeAnalyzerTestCase {
String expression;
expression = String.format("o %s untyped", op.getSyntax());
analyzeIn(cls, expression, 0);
- expression = String.format("s %s untyped", op.getSyntax());
- analyzeIn(cls, expression, 1);
expression = String.format("o %s null", op.getSyntax());
analyzeIn(cls, expression, 0);
- expression = String.format("s %s null", op.getSyntax());
- analyzeIn(cls, expression, 1);
expression = String.format("o %s o", op.getSyntax());
analyzeIn(cls, expression, 0);
- expression = String.format("s %s o", op.getSyntax());
- analyzeIn(cls, expression, 1);
expression = String.format("o %s i", op.getSyntax());
analyzeIn(cls, expression, 1);
+ if (!op.equals(Token.ASSIGN_ADD)) {
+ expression = String.format("s %s untyped", op.getSyntax());
+ analyzeIn(cls, expression, 1);
+ expression = String.format("s %s null", op.getSyntax());
+ analyzeIn(cls, expression, 1);
+ expression = String.format("s %s o", op.getSyntax());
+ analyzeIn(cls, expression, 1);
+ }
}
analyzeIn(cls, "untyped is String", 0);
@@ -699,11 +703,11 @@ public class TypeAnalyzerTest extends TypeAnalyzerTestCase {
public void testLoadInterfaces() {
loadFile("interfaces.dart");
- ClassElement superElement = coreElements.get("Super");
+ ClassElement superElement = (ClassElement)coreElements.get("Super");
assertNotNull("no element for Super", superElement);
assertEquals(object.getType(), superElement.getSupertype());
assertEquals(0, superElement.getInterfaces().size());
- ClassElement sub = coreElements.get("Sub");
+ ClassElement sub = (ClassElement)coreElements.get("Sub");
assertNotNull("no element for Sub", sub);
assertEquals(object.getType(), sub.getSupertype());
assertEquals(1, sub.getInterfaces().size());
@@ -1323,9 +1327,9 @@ public class TypeAnalyzerTest extends TypeAnalyzerTestCase {
analyzeFail("{ void f() {} m(x) {} m(f()); }", TypeErrorCode.VOID);
// Assigning a void expression to a variable.
- analyzeFail("{ void f() {} String x = f(); }", TypeErrorCode.VOID);
- analyzeFail("{ void f() {} String x; x = f(); }", TypeErrorCode.VOID);
- analyzeFail("{ void f() {} String x; x += f(); }", TypeErrorCode.VOID);
+ analyzeFail("{ void f() {} int x = f(); }", TypeErrorCode.VOID);
+ analyzeFail("{ void f() {} int x; x = f(); }", TypeErrorCode.VOID);
+ analyzeFail("{ void f() {} int x; x += f(); }", TypeErrorCode.VOID);
// Misc.
analyzeFail("{ void f() {} 1 + f(); }", TypeErrorCode.VOID);
@@ -1363,4 +1367,27 @@ public class TypeAnalyzerTest extends TypeAnalyzerTestCase {
analyze("{ var val1 = new IA<Bar>(); }");
analyzeFail("{ var val1 = new IA<String>(); }",TypeErrorCode.TYPE_NOT_ASSIGNMENT_COMPATIBLE);
}
+
+ public void testStringConcat() {
+ Map<String, ClassNodeElement> source = loadSource(
+ "class Object {}",
+ "interface Foo {",
+ " operator +(arg1);" +
+ "}",
+ "Foo a = new Foo();",
+ "Foo b = new Foo();",
+ "String s = 'foo';");
+ analyzeClasses(source);
+ analyze("{ var c = a + b; }");
+ analyzeFail("{ var c = s + b; }",
+ TypeErrorCode.PLUS_CANNOT_BE_USED_FOR_STRING_CONCAT);
+ analyzeFail("{ var c = a + s; }",
+ TypeErrorCode.PLUS_CANNOT_BE_USED_FOR_STRING_CONCAT);
+ analyzeFail("var c = 'foo' + 1;",
+ TypeErrorCode.PLUS_CANNOT_BE_USED_FOR_STRING_CONCAT);
+ analyzeFail("var c = 1 + 'foo';",
+ TypeErrorCode.PLUS_CANNOT_BE_USED_FOR_STRING_CONCAT);
+ analyzeFail("var c = 'foo' + 'bar';",
+ TypeErrorCode.PLUS_CANNOT_BE_USED_FOR_STRING_CONCAT);
+ }
}

Powered by Google App Engine
This is Rietveld 408576698