Index: compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java |
diff --git a/compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java b/compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java |
index aafec2bf47f6a7edb05b1baec6ed648153dd3e06..39797f3a86db5fbe87bbd5769e4d6e942db9a6f6 100644 |
--- a/compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java |
+++ b/compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java |
@@ -3,21 +3,14 @@ |
// BSD-style license that can be found in the LICENSE file. |
package com.google.dart.compiler.type; |
-import com.google.common.base.Joiner; |
import com.google.common.collect.Iterables; |
import com.google.common.collect.Lists; |
-import com.google.common.collect.Maps; |
import com.google.common.collect.Sets; |
import com.google.dart.compiler.CommandLineOptions.CompilerOptions; |
import com.google.dart.compiler.CompilerTestCase; |
-import com.google.dart.compiler.DartArtifactProvider; |
import com.google.dart.compiler.DartCompilationError; |
-import com.google.dart.compiler.DartCompiler; |
import com.google.dart.compiler.DartCompilerErrorCode; |
-import com.google.dart.compiler.DartCompilerListener; |
import com.google.dart.compiler.DefaultCompilerConfiguration; |
-import com.google.dart.compiler.MockArtifactProvider; |
-import com.google.dart.compiler.MockLibrarySource; |
import com.google.dart.compiler.ast.ASTVisitor; |
import com.google.dart.compiler.ast.DartArrayAccess; |
import com.google.dart.compiler.ast.DartBinaryExpression; |
@@ -56,8 +49,6 @@ import com.google.dart.compiler.resolver.TypeErrorCode; |
import static com.google.dart.compiler.common.ErrorExpectation.assertErrors; |
import static com.google.dart.compiler.common.ErrorExpectation.errEx; |
-import java.io.Reader; |
-import java.io.StringReader; |
import java.net.URI; |
import java.util.List; |
import java.util.Set; |
@@ -257,8 +248,6 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase { |
public void test_resolveClassMethod() throws Exception { |
AnalyzeLibraryResult libraryResult = |
analyzeLibrary( |
- "Test.dart", |
- Joiner.on("\n").join( |
"class Object {}", |
"class Test {", |
" foo() {", |
@@ -266,7 +255,7 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase { |
" }", |
" f() {", |
" }", |
- "}")); |
+ "}"); |
DartUnit unit = libraryResult.getLibraryUnitResult().getUnits().iterator().next(); |
// find f() invocation |
DartInvocation invocation = findInvocationSimple(unit, "f()"); |
@@ -292,16 +281,14 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase { |
public void test_resolveLocalFunction() throws Exception { |
AnalyzeLibraryResult libraryResult = |
analyzeLibrary( |
- "Test.dart", |
- Joiner.on("\n").join( |
- "class Object {}", |
- "class Test {", |
- " foo() {", |
- " f() {", |
- " }", |
- " f();", |
- " }", |
- "}")); |
+ "class Object {}", |
+ "class Test {", |
+ " foo() {", |
+ " f() {", |
+ " }", |
+ " f();", |
+ " }", |
+ "}"); |
DartUnit unit = libraryResult.getLibraryUnitResult().getUnits().iterator().next(); |
// find f() invocation |
DartInvocation invocation = findInvocationSimple(unit, "f()"); |
@@ -495,7 +482,7 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase { |
* http://code.google.com/p/dart/issues/detail?id=345 |
*/ |
public void test_badTopLevelFactory() throws Exception { |
- AnalyzeLibraryResult libraryResult = analyzeLibrary("Test.dart", "factory foo() {}"); |
+ AnalyzeLibraryResult libraryResult = analyzeLibrary("factory foo() {}"); |
DartUnit unit = libraryResult.getLibraryUnitResult().getUnits().iterator().next(); |
DartMethodDefinition factory = (DartMethodDefinition) unit.getTopLevelNodes().get(0); |
assertNotNull(factory); |
@@ -547,20 +534,18 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase { |
throws Exception { |
AnalyzeLibraryResult libraryResult = |
analyzeLibrary( |
- getName(), |
- makeCode( |
- "interface Foo {", |
- " int fooA;", |
- " void fooB();", |
- "}", |
- "interface Bar {", |
- " void barA();", |
- "}", |
- "class A implements Foo, Bar {", |
- "}", |
- "main() {", |
- " new A();", |
- "}")); |
+ "interface Foo {", |
+ " int fooA;", |
+ " void fooB();", |
+ "}", |
+ "interface Bar {", |
+ " void barA();", |
+ "}", |
+ "class A implements Foo, Bar {", |
+ "}", |
+ "main() {", |
+ " new A();", |
+ "}"); |
assertErrors( |
libraryResult.getTypeErrors(), |
errEx(TypeErrorCode.CONTRETE_CLASS_WITH_UNIMPLEMENTED_MEMBERS, 8, 7, 1)); |
@@ -583,8 +568,6 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase { |
throws Exception { |
AnalyzeLibraryResult libraryResult = |
analyzeLibrary( |
- getName(), |
- makeCode( |
"abstract class A {", |
" abstract void foo();", |
"}", |
@@ -592,7 +575,7 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase { |
"}", |
"main() {", |
" new B();", |
- "}")); |
+ "}"); |
assertErrors( |
libraryResult.getTypeErrors(), |
errEx(TypeErrorCode.CONTRETE_CLASS_WITH_UNIMPLEMENTED_MEMBERS, 4, 7, 1)); |
@@ -612,14 +595,12 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase { |
throws Exception { |
AnalyzeLibraryResult libraryResult = |
analyzeLibrary( |
- getName(), |
- makeCode( |
- "class A {", |
- " abstract void foo();", |
- "}", |
- "main() {", |
- " new A();", |
- "}")); |
+ "class A {", |
+ " abstract void foo();", |
+ "}", |
+ "main() {", |
+ " new A();", |
+ "}"); |
assertErrors( |
libraryResult.getTypeErrors(), |
errEx(TypeErrorCode.CONTRETE_CLASS_WITH_UNIMPLEMENTED_MEMBERS, 1, 7, 1)); |
@@ -635,14 +616,12 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase { |
throws Exception { |
AnalyzeLibraryResult libraryResult = |
analyzeLibrary( |
- getName(), |
- makeCode( |
"class A {", |
" abstract get x;", |
"}", |
"main() {", |
" new A();", |
- "}")); |
+ "}"); |
assertErrors( |
libraryResult.getTypeErrors(), |
errEx(TypeErrorCode.CONTRETE_CLASS_WITH_UNIMPLEMENTED_MEMBERS, 1, 7, 1)); |
@@ -716,14 +695,12 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase { |
throws Exception { |
AnalyzeLibraryResult libraryResult = |
analyzeLibrary( |
- getName(), |
- makeCode( |
- "abstract class A {", |
- " abstract void bar();", |
- "}", |
- "main() {", |
- " new A();", |
- "}")); |
+ "abstract class A {", |
+ " abstract void bar();", |
+ "}", |
+ "main() {", |
+ " new A();", |
+ "}"); |
assertErrors( |
libraryResult.getTypeErrors(), |
errEx(TypeErrorCode.INSTANTIATION_OF_ABSTRACT_CLASS, 5, 7, 1)); |
@@ -736,22 +713,18 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase { |
*/ |
public void test_warnAbstract_onAbstractClass_whenInstantiate_factoryConstructor() |
throws Exception { |
- AnalyzeLibraryResult libraryResult = |
- analyzeLibrary( |
- getName(), |
- makeCode( |
- "abstract class A {", // explicitly abstract |
- " factory A() {", |
- " return null;", |
- " }", |
- "}", |
- "class C {", |
- " foo() {", |
- " return new A();", // no error - factory constructor |
- " }", |
- "}")); |
- assertErrors( |
- libraryResult.getTypeErrors()); |
+ AnalyzeLibraryResult libraryResult = analyzeLibrary( |
+ "abstract class A {", // explicitly abstract |
+ " factory A() {", |
+ " return null;", |
+ " }", |
+ "}", |
+ "class C {", |
+ " foo() {", |
+ " return new A();", // no error - factory constructor |
+ " }", |
+ "}"); |
+ assertErrors(libraryResult.getTypeErrors()); |
} |
/** |
@@ -763,21 +736,18 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase { |
throws Exception { |
AnalyzeLibraryResult libraryResult = |
analyzeLibrary( |
- getName(), |
- makeCode( |
- "abstract class A {", // class is abstract |
- " factory A() {", |
- " return null;", |
- " }", |
- " abstract method();", |
- "}", |
- "class C {", |
- " foo() {", |
- " return new A();", // no error, factory constructor |
- " }", |
- "}")); |
- assertErrors( |
- libraryResult.getTypeErrors()); |
+ "abstract class A {", // class is abstract |
+ " factory A() {", |
+ " return null;", |
+ " }", |
+ " abstract method();", |
+ "}", |
+ "class C {", |
+ " foo() {", |
+ " return new A();", // no error, factory constructor |
+ " }", |
+ "}"); |
+ assertErrors(libraryResult.getTypeErrors()); |
} |
/** |
@@ -786,14 +756,12 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase { |
public void testWarnOnNonVoidSetter() throws Exception { |
AnalyzeLibraryResult libraryResult = |
analyzeLibrary( |
- getName(), |
- makeCode( |
"class A {", |
" void set foo(bool a) {}", |
" set bar(bool a) {}", |
" dynamic set baz(bool a) {}", |
" bool set bob(bool a) {}", |
- "}")); |
+ "}"); |
assertErrors( |
libraryResult.getTypeErrors(), |
errEx(TypeErrorCode.SETTER_RETURN_TYPE, 4, 3, 7), |
@@ -818,14 +786,12 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase { |
public void test_callFunctionFromField() throws Exception { |
AnalyzeLibraryResult libraryResult = |
analyzeLibrary( |
- getName(), |
- makeCode( |
- "class WorkElement {", |
- " Function run;", |
- "}", |
- "foo(WorkElement e) {", |
- " e.run();", |
- "}")); |
+ "class WorkElement {", |
+ " Function run;", |
+ "}", |
+ "foo(WorkElement e) {", |
+ " e.run();", |
+ "}"); |
assertErrors(libraryResult.getTypeErrors()); |
} |
@@ -853,8 +819,6 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase { |
*/ |
public void test_doubleGetterAccess_inForEach() throws Exception { |
AnalyzeLibraryResult libraryResult = analyzeLibrary( |
- getName(), |
- makeCode( |
"class Test {", |
" Iterable get iter {}", |
"}", |
@@ -862,7 +826,7 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase { |
"f() {", |
" for (var v in test.iter) {}", |
"}", |
- "")); |
+ ""); |
assertErrors(libraryResult.getTypeErrors()); |
} |
@@ -873,8 +837,6 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase { |
public void test_invocationArguments() throws Exception { |
AnalyzeLibraryResult libraryResult = |
analyzeLibrary( |
- getName(), |
- makeCode( |
"/* 01 */ foo() {", |
"/* 02 */ f_0_0();", |
"/* 03 */ f_0_0(-1);", |
@@ -898,7 +860,7 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase { |
"f_2_0(r1, r2) {}", |
"f_0_1({n1}) {}", |
"f_0_2({n1, n2}) {}", |
- "")); |
+ ""); |
assertErrors( |
libraryResult.getTypeErrors(), |
errEx(TypeErrorCode.EXTRA_ARGUMENT, 3, 18, 2), |
@@ -916,20 +878,16 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase { |
} |
/** |
- * Test for errors and warnings related to positional and named arguments for required and |
- * optional parameters. |
+ * Test that optional positional and named parameters are handled separately. |
*/ |
public void test_invocationArguments2() throws Exception { |
- AnalyzeLibraryResult libraryResult = |
- analyzeLibrary( |
- getName(), |
- makeCode( |
- "// filler filler filler filler filler filler filler filler filler filler", |
- "func([int np1, int np2, int np3]) {}", |
- "main() {", |
- " func(np1: 1, np2: 2, np3: 2);", |
- "}", |
- "")); |
+ AnalyzeLibraryResult libraryResult = analyzeLibrary( |
+ "// filler filler filler filler filler filler filler filler filler filler", |
+ "func([int np1, int np2, int np3]) {}", |
+ "main() {", |
+ " func(np1: 1, np2: 2, np3: 2);", |
+ "}", |
+ ""); |
assertErrors( |
libraryResult.getTypeErrors(), |
errEx(TypeErrorCode.NO_SUCH_NAMED_PARAMETER, 4, 8, 6), |
@@ -943,27 +901,24 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase { |
public void test_DartNewExpression_getType() throws Exception { |
AnalyzeLibraryResult libraryResult = |
analyzeLibrary( |
- getName(), |
- makeCode( |
- "// filler filler filler filler filler filler filler filler filler filler", |
- "class A {", |
- " A() {}", |
- " A.foo() {}", |
- "}", |
- "var a1 = new A();", |
- "var a2 = new A.foo();", |
- "")); |
+ "// filler filler filler filler filler filler filler filler filler filler", |
+ "class A {", |
+ " A() {}", |
+ " A.foo() {}", |
+ "}", |
+ "var a1 = new A();", |
+ "var a2 = new A.foo();", |
+ ""); |
assertErrors(libraryResult.getErrors()); |
- DartUnit unit = libraryResult.getLibraryUnitResult().getUnit(getName()); |
// new A() |
{ |
- DartNewExpression newExpression = (DartNewExpression) getTopLevelFieldInitializer(unit, 1); |
+ DartNewExpression newExpression = (DartNewExpression) getTopLevelFieldInitializer(testUnit, 1); |
Type newType = newExpression.getType(); |
assertEquals("A", newType.getElement().getName()); |
} |
// new A.foo() |
{ |
- DartNewExpression newExpression = (DartNewExpression) getTopLevelFieldInitializer(unit, 2); |
+ DartNewExpression newExpression = (DartNewExpression) getTopLevelFieldInitializer(testUnit, 2); |
Type newType = newExpression.getType(); |
assertEquals("A", newType.getElement().getName()); |
} |
@@ -988,25 +943,23 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase { |
public void test_setterOnlyProperty_noGetter() throws Exception { |
AnalyzeLibraryResult libraryResult = |
analyzeLibrary( |
- getName(), |
- makeCode( |
- "class SetOnly {", |
- " set foo(arg) {}", |
- "}", |
- "class SetOnlyWrapper {", |
- " SetOnly setOnly;", |
- "}", |
- "", |
- "main() {", |
- " SetOnly setOnly = new SetOnly();", |
- " setOnly.foo = 1;", // 10: OK, use setter |
- " setOnly.foo += 2;", // 11: ERR, no getter |
- " print(setOnly.foo);", // 12: ERR, no getter |
- " var bar;", |
- " bar = setOnly.foo;", // 14: ERR, assignment, but we are not LHS |
- " bar = new SetOnlyWrapper().setOnly.foo;", // 15: ERR, even in chained expression |
- " new SetOnlyWrapper().setOnly.foo = 3;", // 16: OK |
- "}")); |
+ "class SetOnly {", |
+ " set foo(arg) {}", |
+ "}", |
+ "class SetOnlyWrapper {", |
+ " SetOnly setOnly;", |
+ "}", |
+ "", |
+ "main() {", |
+ " SetOnly setOnly = new SetOnly();", |
+ " setOnly.foo = 1;", // 10: OK, use setter |
+ " setOnly.foo += 2;", // 11: ERR, no getter |
+ " print(setOnly.foo);", // 12: ERR, no getter |
+ " var bar;", |
+ " bar = setOnly.foo;", // 14: ERR, assignment, but we are not LHS |
+ " bar = new SetOnlyWrapper().setOnly.foo;", // 15: ERR, even in chained expression |
+ " new SetOnlyWrapper().setOnly.foo = 3;", // 16: OK |
+ "}"); |
assertErrors( |
libraryResult.getTypeErrors(), |
errEx(TypeErrorCode.FIELD_HAS_NO_GETTER, 11, 11, 3), |
@@ -1018,26 +971,22 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase { |
public void test_setterOnlyProperty_normalField() throws Exception { |
AnalyzeLibraryResult libraryResult = |
analyzeLibrary( |
- getName(), |
- makeCode( |
- "class A {", |
- " var foo;", |
- "}", |
- "", |
- "main() {", |
- " A a = new A();", |
- " a.foo = 1;", |
- " a.foo += 2;", |
- " print(a.foo);", |
- "}")); |
+ "class A {", |
+ " var foo;", |
+ "}", |
+ "", |
+ "main() {", |
+ " A a = new A();", |
+ " a.foo = 1;", |
+ " a.foo += 2;", |
+ " print(a.foo);", |
+ "}"); |
assertErrors(libraryResult.getTypeErrors()); |
} |
public void test_setterOnlyProperty_getterInSuper() throws Exception { |
AnalyzeLibraryResult libraryResult = |
analyzeLibrary( |
- getName(), |
- makeCode( |
"class A {", |
" get foo {}", |
"}", |
@@ -1050,15 +999,13 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase { |
" b.foo = 1;", |
" b.foo += 2;", |
" print(b.foo);", |
- "}")); |
+ "}"); |
assertErrors(libraryResult.getTypeErrors()); |
} |
public void test_setterOnlyProperty_getterInInterface() throws Exception { |
AnalyzeLibraryResult libraryResult = |
analyzeLibrary( |
- getName(), |
- makeCode( |
"interface A {", |
" get foo {}", |
"}", |
@@ -1071,7 +1018,7 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase { |
" b.foo = 1;", |
" b.foo += 2;", |
" print(b.foo);", |
- "}")); |
+ "}"); |
assertErrors( |
libraryResult.getTypeErrors(), |
errEx(TypeErrorCode.INSTANTIATION_OF_ABSTRACT_CLASS, 9, 13, 1)); |
@@ -1080,8 +1027,6 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase { |
public void test_getterOnlyProperty_noSetter() throws Exception { |
AnalyzeLibraryResult libraryResult = |
analyzeLibrary( |
- getName(), |
- makeCode( |
"class GetOnly {", |
" get foo {}", |
"}", |
@@ -1098,7 +1043,7 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase { |
" bar = getOnly.foo;", // 14: OK, use getter |
" new GetOnlyWrapper().getOnly.foo = 3;", // 15: ERR, no setter |
" bar = new GetOnlyWrapper().getOnly.foo;", // 16: OK, use getter |
- "}")); |
+ "}"); |
assertErrors( |
libraryResult.getTypeErrors(), |
errEx(TypeErrorCode.FIELD_HAS_NO_SETTER, 11, 11, 3), |
@@ -1109,8 +1054,6 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase { |
public void test_getterOnlyProperty_setterInSuper() throws Exception { |
AnalyzeLibraryResult libraryResult = |
analyzeLibrary( |
- getName(), |
- makeCode( |
"class A {", |
" set foo(arg) {}", |
"}", |
@@ -1123,15 +1066,13 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase { |
" b.foo = 1;", |
" b.foo += 2;", |
" print(b.foo);", |
- "}")); |
+ "}"); |
assertErrors(libraryResult.getTypeErrors()); |
} |
public void test_getterOnlyProperty_setterInInterface() throws Exception { |
AnalyzeLibraryResult libraryResult = |
analyzeLibrary( |
- getName(), |
- makeCode( |
"interface A {", |
" set foo(arg) {}", |
"}", |
@@ -1144,7 +1085,7 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase { |
" b.foo = 1;", |
" b.foo += 2;", |
" print(b.foo);", |
- "}")); |
+ "}"); |
assertErrors( |
libraryResult.getTypeErrors(), |
errEx(TypeErrorCode.INSTANTIATION_OF_ABSTRACT_CLASS, 9, 13, 1)); |
@@ -1228,18 +1169,16 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase { |
public void test_finalField_inClass() throws Exception { |
AnalyzeLibraryResult libraryResult = analyzeLibrary( |
- getName(), |
- makeCode( |
- "// filler filler filler filler filler filler filler filler filler filler", |
- "class A {", |
- " final f;", |
- "}", |
- "main() {", |
- " A a = new A();", |
- " a.f = 0;", // 6: ERR, is final |
- " a.f += 1;", // 7: ERR, is final |
- " print(a.f);", // 8: OK, can read |
- "}")); |
+ "// filler filler filler filler filler filler filler filler filler filler", |
+ "class A {", |
+ " final f;", |
+ "}", |
+ "main() {", |
+ " A a = new A();", |
+ " a.f = 0;", // 6: ERR, is final |
+ " a.f += 1;", // 7: ERR, is final |
+ " print(a.f);", // 8: OK, can read |
+ "}"); |
assertErrors( |
libraryResult.getTypeErrors(), |
errEx(TypeErrorCode.FIELD_IS_FINAL, 7, 5, 1), |
@@ -1248,21 +1187,19 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase { |
public void test_finalField_inInterface() throws Exception { |
AnalyzeLibraryResult libraryResult = analyzeLibrary( |
- getName(), |
- makeCode( |
- "// filler filler filler filler filler filler filler filler filler filler", |
- "interface I default A {", |
- " final f;", |
- "}", |
- "class A implements I {", |
- " var f;", |
- "}", |
- "main() {", |
- " I a = new I();", |
- " a.f = 0;", // 6: ERR, is final |
- " a.f += 1;", // 7: ERR, is final |
- " print(a.f);", // 8: OK, can read |
- "}")); |
+ "// filler filler filler filler filler filler filler filler filler filler", |
+ "interface I default A {", |
+ " final f;", |
+ "}", |
+ "class A implements I {", |
+ " var f;", |
+ "}", |
+ "main() {", |
+ " I a = new I();", |
+ " a.f = 0;", // 6: ERR, is final |
+ " a.f += 1;", // 7: ERR, is final |
+ " print(a.f);", // 8: OK, can read |
+ "}"); |
assertErrors( |
libraryResult.getTypeErrors(), |
errEx(TypeErrorCode.FIELD_IS_FINAL, 10, 5, 1), |
@@ -1271,43 +1208,39 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase { |
public void test_notFinalField() throws Exception { |
AnalyzeLibraryResult libraryResult = analyzeLibrary( |
- getName(), |
- makeCode( |
- "// filler filler filler filler filler filler filler filler filler filler", |
- "interface I default A {", |
- " var f;", |
- "}", |
- "class A implements I {", |
- " var f;", |
- "}", |
- "main() {", |
- " I a = new I();", |
- " a.f = 0;", // 6: OK, field "f" is not final |
- " a.f += 1;", // 7: OK, field "f" is not final |
- " print(a.f);", // 8: OK, can read |
- "}")); |
+ "// filler filler filler filler filler filler filler filler filler filler", |
+ "interface I default A {", |
+ " var f;", |
+ "}", |
+ "class A implements I {", |
+ " var f;", |
+ "}", |
+ "main() {", |
+ " I a = new I();", |
+ " a.f = 0;", // 6: OK, field "f" is not final |
+ " a.f += 1;", // 7: OK, field "f" is not final |
+ " print(a.f);", // 8: OK, can read |
+ "}"); |
assertErrors(libraryResult.getTypeErrors()); |
} |
public void test_constField() throws Exception { |
AnalyzeLibraryResult libraryResult = analyzeLibrary( |
- getName(), |
- makeCode( |
- "// filler filler filler filler filler filler filler filler filler filler", |
- "const f = 1;", |
- "class A {", |
- " const f = 1;", |
- " method() {", |
- " f = 2;", |
- " this.f = 2;", |
- " }", |
- "}", |
- "main() {", |
- " f = 2;", |
- " A a = new A();", |
- " a.f = 2;", |
- "}", |
- "")); |
+ "// filler filler filler filler filler filler filler filler filler filler", |
+ "const f = 1;", |
+ "class A {", |
+ " const f = 1;", |
+ " method() {", |
+ " f = 2;", |
+ " this.f = 2;", |
+ " }", |
+ "}", |
+ "main() {", |
+ " f = 2;", |
+ " A a = new A();", |
+ " a.f = 2;", |
+ "}", |
+ ""); |
assertErrors( |
libraryResult.getErrors(), |
errEx(ResolverErrorCode.CANNOT_ASSIGN_TO_FINAL, 6, 5, 1), |
@@ -1318,13 +1251,11 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase { |
public void test_identicalFunction() throws Exception { |
AnalyzeLibraryResult libraryResult = analyzeLibrary( |
- getName(), |
- makeCode( |
- "// filler filler filler filler filler filler filler filler filler filler", |
- "const A = 1;", |
- "const B = 2;", |
- "const C = identical(A, B);", |
- "")); |
+ "// filler filler filler filler filler filler filler filler filler filler", |
+ "const A = 1;", |
+ "const B = 2;", |
+ "const C = identical(A, B);", |
+ ""); |
assertErrors(libraryResult.getErrors()); |
} |
@@ -1414,55 +1345,48 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase { |
public void test_methodReturnTypes() throws Exception { |
AnalyzeLibraryResult libraryResult = |
analyzeLibrary( |
- getName(), |
- makeCode( |
"// filler filler filler filler filler filler filler filler filler filler", |
"int fA() {}", |
"dynamic fB() {}", |
"void fC() {}", |
"fD() {}", |
- "")); |
+ ""); |
assertErrors(libraryResult.getTypeErrors()); |
- DartUnit unit = libraryResult.getLibraryUnitResult().getUnit(getName()); |
{ |
- DartMethodDefinition fA = (DartMethodDefinition) unit.getTopLevelNodes().get(0); |
+ DartMethodDefinition fA = (DartMethodDefinition) testUnit.getTopLevelNodes().get(0); |
assertEquals("int", fA.getElement().getReturnType().getElement().getName()); |
} |
{ |
- DartMethodDefinition fB = (DartMethodDefinition) unit.getTopLevelNodes().get(1); |
+ DartMethodDefinition fB = (DartMethodDefinition) testUnit.getTopLevelNodes().get(1); |
assertEquals("dynamic", fB.getElement().getReturnType().getElement().getName()); |
} |
{ |
- DartMethodDefinition fC = (DartMethodDefinition) unit.getTopLevelNodes().get(2); |
+ DartMethodDefinition fC = (DartMethodDefinition) testUnit.getTopLevelNodes().get(2); |
assertEquals("void", fC.getElement().getReturnType().getElement().getName()); |
} |
{ |
- DartMethodDefinition fD = (DartMethodDefinition) unit.getTopLevelNodes().get(3); |
+ DartMethodDefinition fD = (DartMethodDefinition) testUnit.getTopLevelNodes().get(3); |
assertEquals("dynamic", fD.getElement().getReturnType().getElement().getName()); |
} |
} |
public void test_bindToLibraryFunctionFirst() throws Exception { |
- AnalyzeLibraryResult libraryResult = |
- analyzeLibrary( |
- getName(), |
- makeCode( |
- "// filler filler filler filler filler filler filler filler filler filler", |
- "foo() {}", |
- "class A {", |
- " foo() {}", |
- "}", |
- "class B extends A {", |
- " bar() {", |
- " foo();", |
- " }", |
- "}", |
- "")); |
- DartUnit unit = libraryResult.getLibraryUnitResult().getUnit(getName()); |
+ analyzeLibrary( |
+ "// filler filler filler filler filler filler filler filler filler filler", |
+ "foo() {}", |
+ "class A {", |
+ " foo() {}", |
+ "}", |
+ "class B extends A {", |
+ " bar() {", |
+ " foo();", |
+ " }", |
+ "}", |
+ ""); |
// Find foo() invocation. |
DartUnqualifiedInvocation invocation; |
{ |
- DartClass classB = (DartClass) unit.getTopLevelNodes().get(2); |
+ DartClass classB = (DartClass) testUnit.getTopLevelNodes().get(2); |
DartMethodDefinition methodBar = (DartMethodDefinition) classB.getMembers().get(0); |
DartExprStmt stmt = (DartExprStmt) methodBar.getFunction().getBody().getStatements().get(0); |
invocation = (DartUnqualifiedInvocation) stmt.getExpression(); |
@@ -1470,7 +1394,7 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase { |
// Check that unqualified foo() invocation is resolved to the top-level (library) function. |
NodeElement element = invocation.getTarget().getElement(); |
assertNotNull(element); |
- assertSame(unit, element.getNode().getParent()); |
+ assertSame(testUnit, element.getNode().getParent()); |
} |
/** |
@@ -1478,13 +1402,12 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase { |
* as an exception. |
*/ |
public void test_invalidImportUri() throws Exception { |
- List<DartCompilationError> errors = |
- analyzeLibrarySourceErrors(makeCode( |
- "// filler filler filler filler filler filler filler filler filler filler", |
- "library test;", |
- "import 'badURI';", |
- "")); |
- assertErrors(errors, errEx(DartCompilerErrorCode.MISSING_SOURCE, 3, 1, 16)); |
+ AnalyzeLibraryResult libraryResult = analyzeLibrary( |
+ "// filler filler filler filler filler filler filler filler filler filler", |
+ "library test;", |
+ "import 'badURI';", |
+ ""); |
+ assertErrors(libraryResult.getErrors(), errEx(DartCompilerErrorCode.MISSING_SOURCE, 3, 1, 16)); |
} |
/** |
@@ -1492,49 +1415,20 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase { |
* as an exception. |
*/ |
public void test_invalidSourceUri() throws Exception { |
- List<DartCompilationError> errors = |
- analyzeLibrarySourceErrors(makeCode( |
- "// filler filler filler filler filler filler filler filler filler filler", |
- "library test;", |
- "part 'badURI';", |
- "")); |
- assertErrors(errors, errEx(DartCompilerErrorCode.MISSING_SOURCE, 3, 1, 14)); |
- } |
- |
- /** |
- * Analyzes source for given library and returns {@link DartCompilationError}s. |
- */ |
- private static List<DartCompilationError> analyzeLibrarySourceErrors(final String code) |
- throws Exception { |
- MockLibrarySource lib = new MockLibrarySource() { |
- @Override |
- public Reader getSourceReader() { |
- return new StringReader(code); |
- } |
- }; |
- DartArtifactProvider provider = new MockArtifactProvider(); |
- final List<DartCompilationError> errors = Lists.newArrayList(); |
- DartCompiler.analyzeLibrary( |
- lib, |
- Maps.<URI, DartUnit>newHashMap(), |
- CHECK_ONLY_CONFIGURATION, |
- provider, |
- new DartCompilerListener.Empty() { |
- @Override |
- public void onError(DartCompilationError event) { |
- errors.add(event); |
- } |
- }); |
- return errors; |
+ AnalyzeLibraryResult libraryResult = analyzeLibrary( |
+ "// filler filler filler filler filler filler filler filler filler filler", |
+ "library test;", |
+ "part 'badURI';", |
+ ""); |
+ assertErrors(libraryResult.getErrors(), errEx(DartCompilerErrorCode.MISSING_SOURCE, 3, 1, 14)); |
} |
public void test_mapLiteralKeysUnique() throws Exception { |
- List<DartCompilationError> errors = |
- analyzeLibrarySourceErrors(makeCode( |
- "// filler filler filler filler filler filler filler filler filler filler", |
- "var m = {'a' : 0, 'b': 1, 'a': 2};", |
- "")); |
- assertErrors(errors, errEx(TypeErrorCode.MAP_LITERAL_KEY_UNIQUE, 2, 27, 3)); |
+ AnalyzeLibraryResult libraryResult = analyzeLibrary( |
+ "// filler filler filler filler filler filler filler filler filler filler", |
+ "var m = {'a' : 0, 'b': 1, 'a': 2};", |
+ ""); |
+ assertErrors(libraryResult.getErrors(), errEx(TypeErrorCode.MAP_LITERAL_KEY_UNIQUE, 2, 27, 3)); |
} |
/** |
@@ -3411,9 +3305,8 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase { |
"}", |
""); |
assertErrors(libraryResult.getErrors()); |
- DartUnit unit = libraryResult.getLibraryUnitResult().getUnit(getName()); |
// find == expression |
- DartExpression expression = findNodeBySource(unit, "new C() == new C()"); |
+ DartExpression expression = findNodeBySource(testUnit, "new C() == new C()"); |
assertNotNull(expression); |
// validate == element |
MethodElement equalsElement = (MethodElement) expression.getElement(); |
@@ -4470,13 +4363,13 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase { |
* http://code.google.com/p/dart/issues/detail?id=3084 |
*/ |
public void test_unresolvedIdentifier_inStatic_notPropertyAccess() throws Exception { |
- AnalyzeLibraryResult libraryResult = analyzeLibrary(makeCode( |
+ AnalyzeLibraryResult libraryResult = analyzeLibrary( |
"// filler filler filler filler filler filler filler filler filler filler", |
"process(x) {}", |
"main() {", |
" unknown = 0;", |
" process(unknown);", |
- "}")); |
+ "}"); |
assertErrors( |
libraryResult.getErrors(), |
errEx(ResolverErrorCode.CANNOT_BE_RESOLVED, 4, 3, 7), |
@@ -4490,7 +4383,7 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase { |
* http://code.google.com/p/dart/issues/detail?id=3084 |
*/ |
public void test_unresolvedIdentifier_inInstance_notPropertyAccess() throws Exception { |
- AnalyzeLibraryResult libraryResult = analyzeLibrary(makeCode( |
+ AnalyzeLibraryResult libraryResult = analyzeLibrary( |
"// filler filler filler filler filler filler filler filler filler filler", |
"process(x) {}", |
"class A {", |
@@ -4498,7 +4391,7 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase { |
" unknown = 0;", |
" process(unknown);", |
" }", |
- "}")); |
+ "}"); |
assertErrors( |
libraryResult.getErrors(), |
errEx(TypeErrorCode.CANNOT_BE_RESOLVED, 5, 5, 7), |
@@ -4510,13 +4403,13 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase { |
* http://code.google.com/p/dart/issues/detail?id=3084 |
*/ |
public void test_unresolvedIdentifier_inStatic_inPropertyAccess() throws Exception { |
- AnalyzeLibraryResult libraryResult = analyzeLibrary(makeCode( |
+ AnalyzeLibraryResult libraryResult = analyzeLibrary( |
"// filler filler filler filler filler filler filler filler filler filler", |
"process(x) {}", |
"main() {", |
" Unknown.foo = 0;", |
" process(Unknown.foo);", |
- "}")); |
+ "}"); |
assertErrors( |
libraryResult.getErrors(), |
errEx(TypeErrorCode.CANNOT_BE_RESOLVED, 4, 3, 7), |
@@ -4529,7 +4422,7 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase { |
* http://code.google.com/p/dart/issues/detail?id=3800 |
*/ |
public void test_unresolvedConstructor() throws Exception { |
- AnalyzeLibraryResult libraryResult = analyzeLibrary(makeCode( |
+ AnalyzeLibraryResult libraryResult = analyzeLibrary( |
"// filler filler filler filler filler filler filler filler filler filler", |
"class A {}", |
"main() {", |
@@ -4537,7 +4430,7 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase { |
" new A.noSuchConstructor(); // warning", |
" new B(); // warning", |
" new B.noSuchConstructor(); // warning", |
- "}")); |
+ "}"); |
assertErrors( |
libraryResult.getErrors(), |
errEx(ResolverErrorCode.NEW_EXPRESSION_NOT_CONSTRUCTOR, 5, 9, 17), |
@@ -4567,7 +4460,7 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase { |
* many other points in the Editor. |
*/ |
public void test_typeForEveryExpression_variable() throws Exception { |
- AnalyzeLibraryResult libraryResult = analyzeLibrary( |
+ analyzeLibrary( |
"// filler filler filler filler filler filler filler filler filler filler", |
"class A {}", |
"process(x) {}", |
@@ -4575,8 +4468,7 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase { |
" A aaa = new A();", |
" process(aaa);", |
"}"); |
- DartUnit unit = libraryResult.getLibraryUnitResult().getUnit(getName()); |
- unit.accept(new ASTVisitor<Void>() { |
+ testUnit.accept(new ASTVisitor<Void>() { |
public Void visitIdentifier(DartIdentifier node) { |
// ignore declaration |
if (node.getParent() instanceof DartDeclaration) { |
@@ -4598,7 +4490,7 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase { |
* many other points in the Editor. |
*/ |
public void test_typeForEveryExpression_typeNode() throws Exception { |
- AnalyzeLibraryResult libraryResult = analyzeLibrary( |
+ analyzeLibrary( |
"// filler filler filler filler filler filler filler filler filler filler", |
"class AAA {", |
" static foo() {}", |
@@ -4606,8 +4498,7 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase { |
"main() {", |
" AAA.foo();", |
"}"); |
- DartUnit unit = libraryResult.getLibraryUnitResult().getUnit(getName()); |
- unit.accept(new ASTVisitor<Void>() { |
+ testUnit.accept(new ASTVisitor<Void>() { |
public Void visitIdentifier(DartIdentifier node) { |
// ignore declaration |
if (node.getParent() instanceof DartDeclaration) { |
@@ -4678,7 +4569,6 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase { |
" method(10, 20, 30, 40);", |
"}"); |
assertErrors(libraryResult.getErrors()); |
- DartUnit unit = libraryResult.getLibraryUnitResult().getUnit(getName()); |
new ArgumentsBindingTester() { |
@Override |
void checkArgs(int invocationIndex) { |
@@ -4703,7 +4593,7 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase { |
} |
} |
} |
- }.doTest(unit); |
+ }.doTest(testUnit); |
} |
public void test_formalParameters_positional_named() throws Exception { |
@@ -4717,7 +4607,6 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase { |
" method(10, 20, d: 40, c: 30);", |
"}"); |
assertErrors(libraryResult.getErrors()); |
- DartUnit unit = libraryResult.getLibraryUnitResult().getUnit(getName()); |
new ArgumentsBindingTester() { |
@Override |
void checkArgs(int invocationIndex) { |
@@ -4748,7 +4637,7 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase { |
} |
} |
} |
- }.doTest(unit); |
+ }.doTest(testUnit); |
} |
/** |
@@ -4759,12 +4648,12 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase { |
* http://code.google.com/p/dart/issues/detail?id=3989 |
*/ |
public void test_constructorName_sameAsMemberName() throws Exception { |
- AnalyzeLibraryResult libraryResult = analyzeLibrary(makeCode( |
+ AnalyzeLibraryResult libraryResult = analyzeLibrary( |
"// filler filler filler filler filler filler filler filler filler filler", |
"class A {", |
" A.foo() {}", |
" foo() {}", |
- "}")); |
+ "}"); |
assertErrors( |
libraryResult.getErrors(), |
errEx(ResolverErrorCode.CONSTRUCTOR_WITH_NAME_OF_MEMBER, 3, 3, 5)); |
@@ -4775,13 +4664,13 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase { |
* http://code.google.com/p/dart/issues/detail?id=3904 |
*/ |
public void test_reifiedClasses() throws Exception { |
- AnalyzeLibraryResult libraryResult = analyzeLibrary(makeCode( |
+ AnalyzeLibraryResult libraryResult = analyzeLibrary( |
"// filler filler filler filler filler filler filler filler filler filler", |
"class A {}", |
"process(x) {}", |
"main() {", |
" process(A);", |
- "}")); |
+ "}"); |
assertErrors(libraryResult.getErrors()); |
} |
@@ -4790,7 +4679,7 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase { |
* http://code.google.com/p/dart/issues/detail?id=3968 |
*/ |
public void test_redirectingFactoryConstructor() throws Exception { |
- AnalyzeLibraryResult libraryResult = analyzeLibrary(makeCode( |
+ AnalyzeLibraryResult libraryResult = analyzeLibrary( |
"// filler filler filler filler filler filler filler filler filler filler", |
"class A {", |
" A() {}", |
@@ -4801,7 +4690,7 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase { |
" factory B.foo() = A;", |
" factory B.bar() = A.named;", |
"}", |
- "")); |
+ ""); |
assertErrors(libraryResult.getErrors()); |
// prepare "class A" |
ClassElement elementA = findNode(DartClass.class, "class A").getElement(); |
@@ -4826,7 +4715,7 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase { |
} |
public void test_redirectingFactoryConstructor_cycle() throws Exception { |
- AnalyzeLibraryResult libraryResult = analyzeLibrary(makeCode( |
+ AnalyzeLibraryResult libraryResult = analyzeLibrary( |
"// filler filler filler filler filler filler filler filler filler filler", |
"class A {", |
" factory A.nameA() = C.nameC;", |
@@ -4837,7 +4726,7 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase { |
"class C {", |
" factory C.nameC() = B.nameB;", |
"}", |
- "")); |
+ ""); |
assertErrors( |
libraryResult.getErrors(), |
errEx(ResolverErrorCode.REDIRECTION_CONSTRUCTOR_CYCLE, 3, 11, 7), |
@@ -4846,7 +4735,7 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase { |
} |
public void test_redirectingFactoryConstructor_notConst_fromConst() throws Exception { |
- AnalyzeLibraryResult libraryResult = analyzeLibrary(makeCode( |
+ AnalyzeLibraryResult libraryResult = analyzeLibrary( |
"// filler filler filler filler filler filler filler filler filler filler", |
"class A {", |
" A.named() {}", |
@@ -4855,7 +4744,7 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase { |
"class B {", |
" const factory B.bar() = A.named;", |
"}", |
- "")); |
+ ""); |
assertErrors( |
libraryResult.getErrors(), |
errEx(ResolverErrorCode.REDIRECTION_CONSTRUCTOR_TARGET_MUST_BE_CONST, 7, 29, 5)); |
@@ -4866,7 +4755,7 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase { |
* http://code.google.com/p/dart/issues/detail?id=4778 |
*/ |
public void test_unqualifiedAccessToGenericTypeField() throws Exception { |
- AnalyzeLibraryResult libraryResult = analyzeLibrary(makeCode( |
+ AnalyzeLibraryResult libraryResult = analyzeLibrary( |
"// filler filler filler filler filler filler filler filler filler filler", |
"class Game {}", |
"class GameRenderer<G extends Game> {", |
@@ -4880,7 +4769,7 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase { |
" var a = game.score;", |
" }", |
"}", |
- "")); |
+ ""); |
assertErrors(libraryResult.getErrors()); |
} |