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

Side by Side Diff: packages/analyzer/test/generated/compile_time_error_code_test.dart

Issue 2990843002: Removed fixed dependencies (Closed)
Patch Set: Created 3 years, 4 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library engine.compile_time_error_code_test; 5 library analyzer.test.generated.compile_time_error_code_test;
6 6
7 import 'package:analyzer/src/generated/error.dart'; 7 import 'package:analyzer/error/error.dart';
8 import 'package:analyzer/src/error/codes.dart';
9 import 'package:analyzer/src/generated/engine.dart';
8 import 'package:analyzer/src/generated/parser.dart' show ParserErrorCode; 10 import 'package:analyzer/src/generated/parser.dart' show ParserErrorCode;
9 import 'package:analyzer/src/generated/source_io.dart'; 11 import 'package:analyzer/src/generated/source_io.dart';
12 import 'package:test_reflective_loader/test_reflective_loader.dart';
13 import 'package:unittest/unittest.dart' show expect;
10 14
11 import '../reflective_tests.dart';
12 import '../utils.dart'; 15 import '../utils.dart';
13 import 'resolver_test.dart'; 16 import 'resolver_test_case.dart';
14 17
15 main() { 18 main() {
16 initializeTestEnvironment(); 19 initializeTestEnvironment();
17 runReflectiveTests(CompileTimeErrorCodeTest); 20 defineReflectiveTests(CompileTimeErrorCodeTest);
18 } 21 }
19 22
20 @reflectiveTest 23 @reflectiveTest
21 class CompileTimeErrorCodeTest extends ResolverTestCase { 24 class CompileTimeErrorCodeTest extends ResolverTestCase {
22 void fail_awaitInWrongContext_sync() { 25 void fail_awaitInWrongContext_sync() {
23 // This test requires better error recovery than we currently have. In 26 // This test requires better error recovery than we currently have. In
24 // particular, we need to be able to distinguish between an await expression 27 // particular, we need to be able to distinguish between an await expression
25 // in the wrong context, and the use of 'await' as an identifier. 28 // in the wrong context, and the use of 'await' as an identifier.
26 Source source = addSource(r''' 29 Source source = addSource(r'''
27 f(x) { 30 f(x) {
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 addNamedSource( 218 addNamedSource(
216 "/lib2.dart", 219 "/lib2.dart",
217 r''' 220 r'''
218 library lib2; 221 library lib2;
219 class N {}'''); 222 class N {}''');
220 computeLibrarySourceErrors(source); 223 computeLibrarySourceErrors(source);
221 assertErrors(source, [CompileTimeErrorCode.AMBIGUOUS_EXPORT]); 224 assertErrors(source, [CompileTimeErrorCode.AMBIGUOUS_EXPORT]);
222 verify([source]); 225 verify([source]);
223 } 226 }
224 227
228 void test_annotationWithNotClass() {
229 Source source = addSource('''
230 class Property {
231 final int value;
232 const Property(this.value);
233 }
234
235 const Property property = const Property(42);
236
237 @property(123)
238 main() {
239 }
240 ''');
241 computeLibrarySourceErrors(source);
242 assertErrors(source, [CompileTimeErrorCode.ANNOTATION_WITH_NON_CLASS]);
243 verify([source]);
244 }
245
246 void test_annotationWithNotClass_prefixed() {
247 addNamedSource(
248 "/annotations.dart",
249 r'''
250 class Property {
251 final int value;
252 const Property(this.value);
253 }
254
255 const Property property = const Property(42);
256 ''');
257 Source source = addSource('''
258 import 'annotations.dart' as pref;
259 @pref.property(123)
260 main() {
261 }
262 ''');
263 computeLibrarySourceErrors(source);
264 assertErrors(source, [CompileTimeErrorCode.ANNOTATION_WITH_NON_CLASS]);
265 verify([source]);
266 }
267
268 void test_assertWithExtraArgument() {
269 // TODO(paulberry): once DEP 37 is turned on by default, this test should
270 // be removed.
271 Source source = addSource('''
272 f(bool x) {
273 assert(x, 'foo');
274 }
275 ''');
276 computeLibrarySourceErrors(source);
277 assertErrors(source, [CompileTimeErrorCode.EXTRA_ARGUMENT_TO_ASSERT]);
278 verify([source]);
279 }
280
225 void test_async_used_as_identifier_in_annotation() { 281 void test_async_used_as_identifier_in_annotation() {
226 Source source = addSource(''' 282 Source source = addSource('''
227 const int async = 0; 283 const int async = 0;
228 f() async { 284 f() async {
229 g(@async x) {} 285 g(@async x) {}
230 g(0); 286 g(0);
231 } 287 }
232 '''); 288 ''');
233 computeLibrarySourceErrors(source); 289 computeLibrarySourceErrors(source);
234 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); 290 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]);
(...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after
837 final int i = f(); 893 final int i = f();
838 const A(); 894 const A();
839 } 895 }
840 int f() { 896 int f() {
841 return 3; 897 return 3;
842 }'''); 898 }''');
843 computeLibrarySourceErrors(source); 899 computeLibrarySourceErrors(source);
844 // TODO(paulberry): the error CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE is 900 // TODO(paulberry): the error CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE is
845 // redundant and ought to be suppressed. 901 // redundant and ought to be suppressed.
846 assertErrors(source, [ 902 assertErrors(source, [
847 CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_FIELD_INITIALIZED_BY_NON_CONST , 903 CompileTimeErrorCode
904 .CONST_CONSTRUCTOR_WITH_FIELD_INITIALIZED_BY_NON_CONST,
848 CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE 905 CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE
849 ]); 906 ]);
850 verify([source]); 907 verify([source]);
851 } 908 }
852 909
853 void test_constConstructorWithFieldInitializedByNonConst_static() { 910 void test_constConstructorWithFieldInitializedByNonConst_static() {
854 Source source = addSource(r''' 911 Source source = addSource(r'''
855 class A { 912 class A {
856 static final int i = f(); 913 static final int i = f();
857 const A(); 914 const A();
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
1002 Source source = addSource(r''' 1059 Source source = addSource(r'''
1003 class A { 1060 class A {
1004 external factory const A(); 1061 external factory const A();
1005 } 1062 }
1006 const x = const A();'''); 1063 const x = const A();''');
1007 computeLibrarySourceErrors(source); 1064 computeLibrarySourceErrors(source);
1008 assertNoErrors(source); 1065 assertNoErrors(source);
1009 verify([source]); 1066 verify([source]);
1010 } 1067 }
1011 1068
1069 void test_constEval_nonStaticField_inGenericClass() {
1070 Source source = addSource('''
1071 class C<T> {
1072 const C();
1073 T get t => null;
1074 }
1075
1076 const x = const C().t;''');
1077 computeLibrarySourceErrors(source);
1078 assertErrors(source,
1079 [CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE]);
1080 verify([source]);
1081 }
1082
1012 void test_constEval_propertyExtraction_targetNotConst() { 1083 void test_constEval_propertyExtraction_targetNotConst() {
1013 Source source = addSource(r''' 1084 Source source = addSource(r'''
1014 class A { 1085 class A {
1015 const A(); 1086 const A();
1016 m() {} 1087 m() {}
1017 } 1088 }
1018 final a = const A(); 1089 final a = const A();
1019 const C = a.m;'''); 1090 const C = a.m;''');
1020 computeLibrarySourceErrors(source); 1091 computeLibrarySourceErrors(source);
1021 assertErrors(source, 1092 assertErrors(source,
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
1191 Source source = addSource(r''' 1262 Source source = addSource(r'''
1192 f(p) { 1263 f(p) {
1193 const C = p; 1264 const C = p;
1194 }'''); 1265 }''');
1195 computeLibrarySourceErrors(source); 1266 computeLibrarySourceErrors(source);
1196 assertErrors(source, 1267 assertErrors(source,
1197 [CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE]); 1268 [CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE]);
1198 verify([source]); 1269 verify([source]);
1199 } 1270 }
1200 1271
1272 void test_constInitializedWithNonConstValue_finalField() {
1273 // Regression test for bug #25526 which previously
1274 // caused two errors to be reported.
1275 Source source = addSource(r'''
1276 class Foo {
1277 final field = [];
1278 foo([int x = field]) {}
1279 }
1280 ''');
1281 computeLibrarySourceErrors(source);
1282 assertErrors(source, [CompileTimeErrorCode.NON_CONSTANT_DEFAULT_VALUE]);
1283 verify([source]);
1284 }
1285
1201 void test_constInitializedWithNonConstValue_missingConstInListLiteral() { 1286 void test_constInitializedWithNonConstValue_missingConstInListLiteral() {
1202 Source source = addSource("const List L = [0];"); 1287 Source source = addSource("const List L = [0];");
1203 computeLibrarySourceErrors(source); 1288 computeLibrarySourceErrors(source);
1204 assertErrors(source, 1289 assertErrors(source,
1205 [CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE]); 1290 [CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE]);
1206 verify([source]); 1291 verify([source]);
1207 } 1292 }
1208 1293
1209 void test_constInitializedWithNonConstValue_missingConstInMapLiteral() { 1294 void test_constInitializedWithNonConstValue_missingConstInMapLiteral() {
1210 Source source = addSource("const Map M = {'a' : 0};"); 1295 Source source = addSource("const Map M = {'a' : 0};");
1211 computeLibrarySourceErrors(source); 1296 computeLibrarySourceErrors(source);
1212 assertErrors(source, 1297 assertErrors(source,
1213 [CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE]); 1298 [CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE]);
1214 verify([source]); 1299 verify([source]);
1215 } 1300 }
1216 1301
1217 void test_constInitializedWithNonConstValueFromDeferredClass() { 1302 void test_constInitializedWithNonConstValueFromDeferredClass() {
1218 resolveWithErrors(<String>[ 1303 resolveWithErrors(<String>[
1219 r''' 1304 r'''
1220 library lib1; 1305 library lib1;
1221 const V = 1;''', 1306 const V = 1;''',
1222 r''' 1307 r'''
1223 library root; 1308 library root;
1224 import 'lib1.dart' deferred as a; 1309 import 'lib1.dart' deferred as a;
1225 const B = a.V;''' 1310 const B = a.V;'''
1226 ], <ErrorCode>[ 1311 ], <ErrorCode>[
1227 CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE_FROM_DEFERR ED_LIBRARY 1312 CompileTimeErrorCode
1313 .CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE_FROM_DEFERRED_LIBRARY
1228 ]); 1314 ]);
1229 } 1315 }
1230 1316
1231 void test_constInitializedWithNonConstValueFromDeferredClass_nested() { 1317 void test_constInitializedWithNonConstValueFromDeferredClass_nested() {
1232 resolveWithErrors(<String>[ 1318 resolveWithErrors(<String>[
1233 r''' 1319 r'''
1234 library lib1; 1320 library lib1;
1235 const V = 1;''', 1321 const V = 1;''',
1236 r''' 1322 r'''
1237 library root; 1323 library root;
1238 import 'lib1.dart' deferred as a; 1324 import 'lib1.dart' deferred as a;
1239 const B = a.V + 1;''' 1325 const B = a.V + 1;'''
1240 ], <ErrorCode>[ 1326 ], <ErrorCode>[
1241 CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE_FROM_DEFERR ED_LIBRARY 1327 CompileTimeErrorCode
1328 .CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE_FROM_DEFERRED_LIBRARY
1242 ]); 1329 ]);
1243 } 1330 }
1244 1331
1245 void test_constInstanceField() { 1332 void test_constInstanceField() {
1246 Source source = addSource(r''' 1333 Source source = addSource(r'''
1247 class C { 1334 class C {
1248 const int f = 0; 1335 const int f = 0;
1249 }'''); 1336 }''');
1250 computeLibrarySourceErrors(source); 1337 computeLibrarySourceErrors(source);
1251 assertErrors(source, [CompileTimeErrorCode.CONST_INSTANCE_FIELD]); 1338 assertErrors(source, [CompileTimeErrorCode.CONST_INSTANCE_FIELD]);
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
1371 Source source = addSource(r''' 1458 Source source = addSource(r'''
1372 class T { 1459 class T {
1373 T(a, b, {c, d}) {} 1460 T(a, b, {c, d}) {}
1374 } 1461 }
1375 f() { return const T(0, 1, c: 2, d: 3); }'''); 1462 f() { return const T(0, 1, c: 2, d: 3); }''');
1376 computeLibrarySourceErrors(source); 1463 computeLibrarySourceErrors(source);
1377 assertErrors(source, [CompileTimeErrorCode.CONST_WITH_NON_CONST]); 1464 assertErrors(source, [CompileTimeErrorCode.CONST_WITH_NON_CONST]);
1378 verify([source]); 1465 verify([source]);
1379 } 1466 }
1380 1467
1468 void test_constWithNonConst_with() {
1469 Source source = addSource(r'''
1470 class B {
1471 const B();
1472 }
1473 class C = B with M;
1474 class M {}
1475 const x = const C();
1476 main() {
1477 print(x);
1478 }
1479 ''');
1480 computeLibrarySourceErrors(source);
1481 assertErrors(source, [CompileTimeErrorCode.CONST_WITH_NON_CONST]);
1482 verify([source]);
1483 }
1484
1381 void test_constWithNonConstantArgument_annotation() { 1485 void test_constWithNonConstantArgument_annotation() {
1382 Source source = addSource(r''' 1486 Source source = addSource(r'''
1383 class A { 1487 class A {
1384 const A(int p); 1488 const A(int p);
1385 } 1489 }
1386 var v = 42; 1490 var v = 42;
1387 @A(v) 1491 @A(v)
1388 main() { 1492 main() {
1389 }'''); 1493 }''');
1390 computeLibrarySourceErrors(source); 1494 computeLibrarySourceErrors(source);
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
1574 1678
1575 class A {}'''); 1679 class A {}''');
1576 Source sourceB = addNamedSource( 1680 Source sourceB = addNamedSource(
1577 "/b.dart", 1681 "/b.dart",
1578 r''' 1682 r'''
1579 part of lib; 1683 part of lib;
1580 1684
1581 class A {}'''); 1685 class A {}''');
1582 computeLibrarySourceErrors(librarySource); 1686 computeLibrarySourceErrors(librarySource);
1583 assertErrors(sourceB, [CompileTimeErrorCode.DUPLICATE_DEFINITION]); 1687 assertErrors(sourceB, [CompileTimeErrorCode.DUPLICATE_DEFINITION]);
1688 assertNoErrors(librarySource);
1584 verify([librarySource, sourceA, sourceB]); 1689 verify([librarySource, sourceA, sourceB]);
1585 } 1690 }
1586 1691
1587 void test_duplicateDefinition_catch() { 1692 void test_duplicateDefinition_catch() {
1588 Source source = addSource(r''' 1693 Source source = addSource(r'''
1589 main() { 1694 main() {
1590 try {} catch (e, e) {} 1695 try {} catch (e, e) {}
1591 }'''); 1696 }''');
1592 computeLibrarySourceErrors(source); 1697 computeLibrarySourceErrors(source);
1593 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION]); 1698 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION]);
(...skipping 26 matching lines...) Expand all
1620 Source source = addSource(r''' 1725 Source source = addSource(r'''
1621 class A { 1726 class A {
1622 m() {} 1727 m() {}
1623 m() {} 1728 m() {}
1624 }'''); 1729 }''');
1625 computeLibrarySourceErrors(source); 1730 computeLibrarySourceErrors(source);
1626 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION]); 1731 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION]);
1627 verify([source]); 1732 verify([source]);
1628 } 1733 }
1629 1734
1735 void test_duplicateDefinition_inPart() {
1736 Source librarySource = addNamedSource(
1737 "/lib.dart",
1738 r'''
1739 library test;
1740 part 'a.dart';
1741 class A {}''');
1742 Source sourceA = addNamedSource(
1743 "/a.dart",
1744 r'''
1745 part of test;
1746 class A {}''');
1747 computeLibrarySourceErrors(librarySource);
1748 assertErrors(sourceA, [CompileTimeErrorCode.DUPLICATE_DEFINITION]);
1749 assertNoErrors(librarySource);
1750 verify([librarySource, sourceA]);
1751 }
1752
1630 void test_duplicateDefinition_locals_inCase() { 1753 void test_duplicateDefinition_locals_inCase() {
1631 Source source = addSource(r''' 1754 Source source = addSource(r'''
1632 main() { 1755 main() {
1633 switch(1) { 1756 switch(1) {
1634 case 1: 1757 case 1:
1635 var a; 1758 var a;
1636 var a; 1759 var a;
1637 } 1760 }
1638 }'''); 1761 }''');
1639 computeLibrarySourceErrors(source); 1762 computeLibrarySourceErrors(source);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1671 m() { 1794 m() {
1672 int a; 1795 int a;
1673 int a; 1796 int a;
1674 } 1797 }
1675 }'''); 1798 }''');
1676 computeLibrarySourceErrors(source); 1799 computeLibrarySourceErrors(source);
1677 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION]); 1800 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION]);
1678 verify([source]); 1801 verify([source]);
1679 } 1802 }
1680 1803
1804 void test_duplicateDefinition_parameters_inConstructor() {
1805 Source source = addSource(r'''
1806 class A {
1807 int a;
1808 A(int a, this.a);
1809 }''');
1810 computeLibrarySourceErrors(source);
1811 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION]);
1812 verify([source]);
1813 }
1814
1681 void test_duplicateDefinition_parameters_inFunctionTypeAlias() { 1815 void test_duplicateDefinition_parameters_inFunctionTypeAlias() {
1682 Source source = addSource(r''' 1816 Source source = addSource(r'''
1683 typedef F(int a, double a); 1817 typedef F(int a, double a);
1684 '''); 1818 ''');
1685 computeLibrarySourceErrors(source); 1819 computeLibrarySourceErrors(source);
1686 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION]); 1820 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION]);
1687 verify([source]); 1821 verify([source]);
1688 } 1822 }
1689 1823
1690 void test_duplicateDefinition_parameters_inLocalFunction() { 1824 void test_duplicateDefinition_parameters_inLocalFunction() {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1734 } 1868 }
1735 class B extends A { 1869 class B extends A {
1736 static int get x => 0; 1870 static int get x => 0;
1737 }'''); 1871 }''');
1738 computeLibrarySourceErrors(source); 1872 computeLibrarySourceErrors(source);
1739 assertErrors( 1873 assertErrors(
1740 source, [CompileTimeErrorCode.DUPLICATE_DEFINITION_INHERITANCE]); 1874 source, [CompileTimeErrorCode.DUPLICATE_DEFINITION_INHERITANCE]);
1741 verify([source]); 1875 verify([source]);
1742 } 1876 }
1743 1877
1744 void test_duplicateDefinitionInheritance_instanceGetterAbstract_staticGetter() { 1878 void
1879 test_duplicateDefinitionInheritance_instanceGetterAbstract_staticGetter() {
1745 Source source = addSource(r''' 1880 Source source = addSource(r'''
1746 abstract class A { 1881 abstract class A {
1747 int get x; 1882 int get x;
1748 } 1883 }
1749 class B extends A { 1884 class B extends A {
1750 static int get x => 0; 1885 static int get x => 0;
1751 }'''); 1886 }''');
1752 computeLibrarySourceErrors(source); 1887 computeLibrarySourceErrors(source);
1753 assertErrors( 1888 assertErrors(
1754 source, [CompileTimeErrorCode.DUPLICATE_DEFINITION_INHERITANCE]); 1889 source, [CompileTimeErrorCode.DUPLICATE_DEFINITION_INHERITANCE]);
1755 verify([source]); 1890 verify([source]);
1756 } 1891 }
1757 1892
1758 void test_duplicateDefinitionInheritance_instanceMethod_staticMethod() { 1893 void test_duplicateDefinitionInheritance_instanceMethod_staticMethod() {
1759 Source source = addSource(r''' 1894 Source source = addSource(r'''
1760 class A { 1895 class A {
1761 x() {} 1896 x() {}
1762 } 1897 }
1763 class B extends A { 1898 class B extends A {
1764 static x() {} 1899 static x() {}
1765 }'''); 1900 }''');
1766 computeLibrarySourceErrors(source); 1901 computeLibrarySourceErrors(source);
1767 assertErrors( 1902 assertErrors(
1768 source, [CompileTimeErrorCode.DUPLICATE_DEFINITION_INHERITANCE]); 1903 source, [CompileTimeErrorCode.DUPLICATE_DEFINITION_INHERITANCE]);
1769 verify([source]); 1904 verify([source]);
1770 } 1905 }
1771 1906
1772 void test_duplicateDefinitionInheritance_instanceMethodAbstract_staticMethod() { 1907 void
1908 test_duplicateDefinitionInheritance_instanceMethodAbstract_staticMethod() {
1773 Source source = addSource(r''' 1909 Source source = addSource(r'''
1774 abstract class A { 1910 abstract class A {
1775 x(); 1911 x();
1776 } 1912 }
1777 abstract class B extends A { 1913 abstract class B extends A {
1778 static x() {} 1914 static x() {}
1779 }'''); 1915 }''');
1780 computeLibrarySourceErrors(source); 1916 computeLibrarySourceErrors(source);
1781 assertErrors( 1917 assertErrors(
1782 source, [CompileTimeErrorCode.DUPLICATE_DEFINITION_INHERITANCE]); 1918 source, [CompileTimeErrorCode.DUPLICATE_DEFINITION_INHERITANCE]);
1783 verify([source]); 1919 verify([source]);
1784 } 1920 }
1785 1921
1786 void test_duplicateDefinitionInheritance_instanceSetter_staticSetter() { 1922 void test_duplicateDefinitionInheritance_instanceSetter_staticSetter() {
1787 Source source = addSource(r''' 1923 Source source = addSource(r'''
1788 class A { 1924 class A {
1789 set x(value) {} 1925 set x(value) {}
1790 } 1926 }
1791 class B extends A { 1927 class B extends A {
1792 static set x(value) {} 1928 static set x(value) {}
1793 }'''); 1929 }''');
1794 computeLibrarySourceErrors(source); 1930 computeLibrarySourceErrors(source);
1795 assertErrors( 1931 assertErrors(
1796 source, [CompileTimeErrorCode.DUPLICATE_DEFINITION_INHERITANCE]); 1932 source, [CompileTimeErrorCode.DUPLICATE_DEFINITION_INHERITANCE]);
1797 verify([source]); 1933 verify([source]);
1798 } 1934 }
1799 1935
1800 void test_duplicateDefinitionInheritance_instanceSetterAbstract_staticSetter() { 1936 void
1937 test_duplicateDefinitionInheritance_instanceSetterAbstract_staticSetter() {
1801 Source source = addSource(r''' 1938 Source source = addSource(r'''
1802 abstract class A { 1939 abstract class A {
1803 set x(value); 1940 set x(value);
1804 } 1941 }
1805 class B extends A { 1942 class B extends A {
1806 static set x(value) {} 1943 static set x(value) {}
1807 }'''); 1944 }''');
1808 computeLibrarySourceErrors(source); 1945 computeLibrarySourceErrors(source);
1809 assertErrors( 1946 assertErrors(
1810 source, [CompileTimeErrorCode.DUPLICATE_DEFINITION_INHERITANCE]); 1947 source, [CompileTimeErrorCode.DUPLICATE_DEFINITION_INHERITANCE]);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1874 assertErrors(source, [ 2011 assertErrors(source, [
1875 CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS, 2012 CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS,
1876 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT 2013 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT
1877 ]); 2014 ]);
1878 verify([source]); 2015 verify([source]);
1879 } 2016 }
1880 2017
1881 void test_extendsDisallowedClass_class_double() { 2018 void test_extendsDisallowedClass_class_double() {
1882 Source source = addSource("class A extends double {}"); 2019 Source source = addSource("class A extends double {}");
1883 computeLibrarySourceErrors(source); 2020 computeLibrarySourceErrors(source);
1884 assertErrors(source, [ 2021 assertErrors(source, [CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS]);
1885 CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS,
1886 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT
1887 ]);
1888 verify([source]); 2022 verify([source]);
1889 } 2023 }
1890 2024
1891 void test_extendsDisallowedClass_class_int() { 2025 void test_extendsDisallowedClass_class_int() {
1892 Source source = addSource("class A extends int {}"); 2026 Source source = addSource("class A extends int {}");
1893 computeLibrarySourceErrors(source); 2027 computeLibrarySourceErrors(source);
1894 assertErrors(source, [ 2028 assertErrors(source, [
1895 CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS, 2029 CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS,
1896 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT 2030 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT
1897 ]); 2031 ]);
1898 verify([source]); 2032 verify([source]);
1899 } 2033 }
1900 2034
1901 void test_extendsDisallowedClass_class_Null() { 2035 void test_extendsDisallowedClass_class_Null() {
1902 Source source = addSource("class A extends Null {}"); 2036 Source source = addSource("class A extends Null {}");
1903 computeLibrarySourceErrors(source); 2037 computeLibrarySourceErrors(source);
1904 assertErrors(source, [ 2038 assertErrors(source, [
1905 CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS, 2039 CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS,
1906 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT 2040 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT
1907 ]); 2041 ]);
1908 verify([source]); 2042 verify([source]);
1909 } 2043 }
1910 2044
1911 void test_extendsDisallowedClass_class_num() { 2045 void test_extendsDisallowedClass_class_num() {
1912 Source source = addSource("class A extends num {}"); 2046 Source source = addSource("class A extends num {}");
1913 computeLibrarySourceErrors(source); 2047 computeLibrarySourceErrors(source);
1914 assertErrors(source, [ 2048 assertErrors(source, [CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS]);
1915 CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS,
1916 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT
1917 ]);
1918 verify([source]); 2049 verify([source]);
1919 } 2050 }
1920 2051
1921 void test_extendsDisallowedClass_class_String() { 2052 void test_extendsDisallowedClass_class_String() {
1922 Source source = addSource("class A extends String {}"); 2053 Source source = addSource("class A extends String {}");
1923 computeLibrarySourceErrors(source); 2054 computeLibrarySourceErrors(source);
1924 assertErrors(source, [ 2055 assertErrors(source, [
1925 CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS, 2056 CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS,
1926 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT 2057 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT
1927 ]); 2058 ]);
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
2026 const A(); 2157 const A();
2027 } 2158 }
2028 class B extends A { 2159 class B extends A {
2029 const B() : super(0); 2160 const B() : super(0);
2030 }'''); 2161 }''');
2031 computeLibrarySourceErrors(source); 2162 computeLibrarySourceErrors(source);
2032 assertErrors(source, [CompileTimeErrorCode.EXTRA_POSITIONAL_ARGUMENTS]); 2163 assertErrors(source, [CompileTimeErrorCode.EXTRA_POSITIONAL_ARGUMENTS]);
2033 verify([source]); 2164 verify([source]);
2034 } 2165 }
2035 2166
2167 void test_fieldFormalParameter_assignedInInitializer() {
2168 Source source = addSource(r'''
2169 class A {
2170 int x;
2171 A(this.x) : x = 3 {}
2172 }''');
2173 computeLibrarySourceErrors(source);
2174 assertErrors(source,
2175 [CompileTimeErrorCode.FIELD_INITIALIZED_IN_PARAMETER_AND_INITIALIZER]);
2176 verify([source]);
2177 }
2178
2036 void test_fieldInitializedByMultipleInitializers() { 2179 void test_fieldInitializedByMultipleInitializers() {
2037 Source source = addSource(r''' 2180 Source source = addSource(r'''
2038 class A { 2181 class A {
2039 int x; 2182 int x;
2040 A() : x = 0, x = 1 {} 2183 A() : x = 0, x = 1 {}
2041 }'''); 2184 }''');
2042 computeLibrarySourceErrors(source); 2185 computeLibrarySourceErrors(source);
2043 assertErrors(source, 2186 assertErrors(source,
2044 [CompileTimeErrorCode.FIELD_INITIALIZED_BY_MULTIPLE_INITIALIZERS]); 2187 [CompileTimeErrorCode.FIELD_INITIALIZED_BY_MULTIPLE_INITIALIZERS]);
2045 verify([source]); 2188 verify([source]);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
2083 computeLibrarySourceErrors(source); 2226 computeLibrarySourceErrors(source);
2084 assertErrors(source, 2227 assertErrors(source,
2085 [CompileTimeErrorCode.FIELD_INITIALIZED_IN_PARAMETER_AND_INITIALIZER]); 2228 [CompileTimeErrorCode.FIELD_INITIALIZED_IN_PARAMETER_AND_INITIALIZER]);
2086 verify([source]); 2229 verify([source]);
2087 } 2230 }
2088 2231
2089 void test_fieldInitializerFactoryConstructor() { 2232 void test_fieldInitializerFactoryConstructor() {
2090 Source source = addSource(r''' 2233 Source source = addSource(r'''
2091 class A { 2234 class A {
2092 int x; 2235 int x;
2093 factory A(this.x) {} 2236 factory A(this.x) => null;
2094 }'''); 2237 }''');
2095 computeLibrarySourceErrors(source); 2238 computeLibrarySourceErrors(source);
2096 assertErrors( 2239 assertErrors(
2097 source, [CompileTimeErrorCode.FIELD_INITIALIZER_FACTORY_CONSTRUCTOR]); 2240 source, [CompileTimeErrorCode.FIELD_INITIALIZER_FACTORY_CONSTRUCTOR]);
2098 verify([source]); 2241 verify([source]);
2099 } 2242 }
2100 2243
2101 void test_fieldInitializerOutsideConstructor() { 2244 void test_fieldInitializerOutsideConstructor() {
2102 // TODO(brianwilkerson) Fix the duplicate error messages. 2245 // TODO(brianwilkerson) Fix the duplicate error messages.
2103 Source source = addSource(r''' 2246 Source source = addSource(r'''
(...skipping 14 matching lines...) Expand all
2118 class A { 2261 class A {
2119 int x; 2262 int x;
2120 m([this.x]) {} 2263 m([this.x]) {}
2121 }'''); 2264 }''');
2122 computeLibrarySourceErrors(source); 2265 computeLibrarySourceErrors(source);
2123 assertErrors( 2266 assertErrors(
2124 source, [CompileTimeErrorCode.FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR]); 2267 source, [CompileTimeErrorCode.FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR]);
2125 verify([source]); 2268 verify([source]);
2126 } 2269 }
2127 2270
2271 void test_fieldInitializerOutsideConstructor_inFunctionTypeParameter() {
2272 Source source = addSource(r'''
2273 class A {
2274 int x;
2275 A(int p(this.x));
2276 }''');
2277 computeLibrarySourceErrors(source);
2278 assertErrors(
2279 source, [CompileTimeErrorCode.FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR]);
2280 verify([source]);
2281 }
2282
2128 void test_fieldInitializerRedirectingConstructor_afterRedirection() { 2283 void test_fieldInitializerRedirectingConstructor_afterRedirection() {
2129 Source source = addSource(r''' 2284 Source source = addSource(r'''
2130 class A { 2285 class A {
2131 int x; 2286 int x;
2132 A.named() {} 2287 A.named() {}
2133 A() : this.named(), x = 42; 2288 A() : this.named(), x = 42;
2134 }'''); 2289 }''');
2135 computeLibrarySourceErrors(source); 2290 computeLibrarySourceErrors(source);
2136 assertErrors(source, 2291 assertErrors(source,
2137 [CompileTimeErrorCode.FIELD_INITIALIZER_REDIRECTING_CONSTRUCTOR]); 2292 [CompileTimeErrorCode.FIELD_INITIALIZER_REDIRECTING_CONSTRUCTOR]);
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
2196 verify([source]); 2351 verify([source]);
2197 } 2352 }
2198 2353
2199 void test_finalInitializedMultipleTimes_initializingFormals() { 2354 void test_finalInitializedMultipleTimes_initializingFormals() {
2200 Source source = addSource(r''' 2355 Source source = addSource(r'''
2201 class A { 2356 class A {
2202 final x; 2357 final x;
2203 A(this.x, this.x) {} 2358 A(this.x, this.x) {}
2204 }'''); 2359 }''');
2205 computeLibrarySourceErrors(source); 2360 computeLibrarySourceErrors(source);
2206 assertErrors( 2361 // TODO(brianwilkerson) There should only be one error here.
2207 source, [CompileTimeErrorCode.FINAL_INITIALIZED_MULTIPLE_TIMES]); 2362 assertErrors(source, [
2363 CompileTimeErrorCode.DUPLICATE_DEFINITION,
2364 CompileTimeErrorCode.FINAL_INITIALIZED_MULTIPLE_TIMES
2365 ]);
2208 verify([source]); 2366 verify([source]);
2209 } 2367 }
2210 2368
2211 void test_finalNotInitialized_instanceField_const_static() { 2369 void test_finalNotInitialized_instanceField_const_static() {
2212 Source source = addSource(r''' 2370 Source source = addSource(r'''
2213 class A { 2371 class A {
2214 static const F; 2372 static const F;
2215 }'''); 2373 }''');
2216 computeLibrarySourceErrors(source); 2374 computeLibrarySourceErrors(source);
2217 assertErrors(source, [CompileTimeErrorCode.CONST_NOT_INITIALIZED]); 2375 assertErrors(source, [CompileTimeErrorCode.CONST_NOT_INITIALIZED]);
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
2547 class A { 2705 class A {
2548 static var F = m(); 2706 static var F = m();
2549 m() {} 2707 m() {}
2550 }'''); 2708 }''');
2551 computeLibrarySourceErrors(source); 2709 computeLibrarySourceErrors(source);
2552 assertErrors( 2710 assertErrors(
2553 source, [CompileTimeErrorCode.IMPLICIT_THIS_REFERENCE_IN_INITIALIZER]); 2711 source, [CompileTimeErrorCode.IMPLICIT_THIS_REFERENCE_IN_INITIALIZER]);
2554 verify([source]); 2712 verify([source]);
2555 } 2713 }
2556 2714
2557 void test_implicitThisReferenceInInitializer_redirectingConstructorInvocation( ) { 2715 void
2716 test_implicitThisReferenceInInitializer_redirectingConstructorInvocation() {
2558 Source source = addSource(r''' 2717 Source source = addSource(r'''
2559 class A { 2718 class A {
2560 A(p) {} 2719 A(p) {}
2561 A.named() : this(f); 2720 A.named() : this(f);
2562 var f; 2721 var f;
2563 }'''); 2722 }''');
2564 computeLibrarySourceErrors(source); 2723 computeLibrarySourceErrors(source);
2565 assertErrors( 2724 assertErrors(
2566 source, [CompileTimeErrorCode.IMPLICIT_THIS_REFERENCE_IN_INITIALIZER]); 2725 source, [CompileTimeErrorCode.IMPLICIT_THIS_REFERENCE_IN_INITIALIZER]);
2567 verify([source]); 2726 verify([source]);
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
2913 Source source = addSource(r''' 3072 Source source = addSource(r'''
2914 import 'lib.dart' as p; 3073 import 'lib.dart' as p;
2915 @p.V 3074 @p.V
2916 main() { 3075 main() {
2917 }'''); 3076 }''');
2918 computeLibrarySourceErrors(source); 3077 computeLibrarySourceErrors(source);
2919 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]); 3078 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]);
2920 verify([source]); 3079 verify([source]);
2921 } 3080 }
2922 3081
2923 void test_invalidAnnotation_importWithPrefix_notVariableOrConstructorInvocatio n() { 3082 void
3083 test_invalidAnnotation_importWithPrefix_notVariableOrConstructorInvocation () {
2924 addNamedSource( 3084 addNamedSource(
2925 "/lib.dart", 3085 "/lib.dart",
2926 r''' 3086 r'''
2927 library lib; 3087 library lib;
2928 typedef V();'''); 3088 typedef V();''');
2929 Source source = addSource(r''' 3089 Source source = addSource(r'''
2930 import 'lib.dart' as p; 3090 import 'lib.dart' as p;
2931 @p.V 3091 @p.V
2932 main() { 3092 main() {
2933 }'''); 3093 }''');
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
3073 }'''); 3233 }''');
3074 computeLibrarySourceErrors(source); 3234 computeLibrarySourceErrors(source);
3075 assertErrors(source, [CompileTimeErrorCode.INVALID_CONSTRUCTOR_NAME]); 3235 assertErrors(source, [CompileTimeErrorCode.INVALID_CONSTRUCTOR_NAME]);
3076 // no verify() call, "B" is not resolved 3236 // no verify() call, "B" is not resolved
3077 } 3237 }
3078 3238
3079 void test_invalidFactoryNameNotAClass_notClassName() { 3239 void test_invalidFactoryNameNotAClass_notClassName() {
3080 Source source = addSource(r''' 3240 Source source = addSource(r'''
3081 int B; 3241 int B;
3082 class A { 3242 class A {
3083 factory B() {} 3243 factory B() => null;
3084 }'''); 3244 }''');
3085 computeLibrarySourceErrors(source); 3245 computeLibrarySourceErrors(source);
3086 assertErrors( 3246 assertErrors(
3087 source, [CompileTimeErrorCode.INVALID_FACTORY_NAME_NOT_A_CLASS]); 3247 source, [CompileTimeErrorCode.INVALID_FACTORY_NAME_NOT_A_CLASS]);
3088 verify([source]); 3248 verify([source]);
3089 } 3249 }
3090 3250
3091 void test_invalidFactoryNameNotAClass_notEnclosingClassName() { 3251 void test_invalidFactoryNameNotAClass_notEnclosingClassName() {
3092 Source source = addSource(r''' 3252 Source source = addSource(r'''
3093 class A { 3253 class A {
3094 factory B() {} 3254 factory B() => null;
3095 }'''); 3255 }''');
3096 computeLibrarySourceErrors(source); 3256 computeLibrarySourceErrors(source);
3097 assertErrors( 3257 assertErrors(
3098 source, [CompileTimeErrorCode.INVALID_FACTORY_NAME_NOT_A_CLASS]); 3258 source, [CompileTimeErrorCode.INVALID_FACTORY_NAME_NOT_A_CLASS]);
3099 // no verify() call, "B" is not resolved 3259 // no verify() call, "B" is not resolved
3100 } 3260 }
3101 3261
3102 void test_invalidModifierOnConstructor_async() { 3262 void test_invalidModifierOnConstructor_async() {
3103 Source source = addSource(r''' 3263 Source source = addSource(r'''
3104 class A { 3264 class A {
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
3438 class A { 3598 class A {
3439 get x => 0; 3599 get x => 0;
3440 x(y) {} 3600 x(y) {}
3441 }'''); 3601 }''');
3442 computeLibrarySourceErrors(source); 3602 computeLibrarySourceErrors(source);
3443 assertErrors( 3603 assertErrors(
3444 source, [CompileTimeErrorCode.METHOD_AND_GETTER_WITH_SAME_NAME]); 3604 source, [CompileTimeErrorCode.METHOD_AND_GETTER_WITH_SAME_NAME]);
3445 verify([source]); 3605 verify([source]);
3446 } 3606 }
3447 3607
3448 void test_missingEnumConstantInSwitch() {
3449 Source source = addSource(r'''
3450 enum E { ONE, TWO, THREE, FOUR }
3451 bool odd(E e) {
3452 switch (e) {
3453 case E.ONE:
3454 case E.THREE: return true;
3455 }
3456 return false;
3457 }''');
3458 computeLibrarySourceErrors(source);
3459 assertErrors(source, [
3460 CompileTimeErrorCode.MISSING_ENUM_CONSTANT_IN_SWITCH,
3461 CompileTimeErrorCode.MISSING_ENUM_CONSTANT_IN_SWITCH
3462 ]);
3463 verify([source]);
3464 }
3465
3466 void test_mixinDeclaresConstructor_classDeclaration() { 3608 void test_mixinDeclaresConstructor_classDeclaration() {
3467 Source source = addSource(r''' 3609 Source source = addSource(r'''
3468 class A { 3610 class A {
3469 A() {} 3611 A() {}
3470 } 3612 }
3471 class B extends Object with A {}'''); 3613 class B extends Object with A {}''');
3472 computeLibrarySourceErrors(source); 3614 computeLibrarySourceErrors(source);
3473 assertErrors(source, [CompileTimeErrorCode.MIXIN_DECLARES_CONSTRUCTOR]); 3615 assertErrors(source, [CompileTimeErrorCode.MIXIN_DECLARES_CONSTRUCTOR]);
3474 verify([source]); 3616 verify([source]);
3475 } 3617 }
(...skipping 1086 matching lines...) Expand 10 before | Expand all | Expand 10 after
4562 library lib1; 4704 library lib1;
4563 const int c = 1;''', 4705 const int c = 1;''',
4564 r''' 4706 r'''
4565 library root; 4707 library root;
4566 import 'lib1.dart' deferred as a; 4708 import 'lib1.dart' deferred as a;
4567 class A { 4709 class A {
4568 final int x; 4710 final int x;
4569 const A() : x = a.c; 4711 const A() : x = a.c;
4570 }''' 4712 }'''
4571 ], <ErrorCode>[ 4713 ], <ErrorCode>[
4572 CompileTimeErrorCode.NON_CONSTANT_VALUE_IN_INITIALIZER_FROM_DEFERRED_LIBRA RY 4714 CompileTimeErrorCode
4715 .NON_CONSTANT_VALUE_IN_INITIALIZER_FROM_DEFERRED_LIBRARY
4573 ]); 4716 ]);
4574 } 4717 }
4575 4718
4576 void test_nonConstValueInInitializerFromDeferredLibrary_field_nested() { 4719 void test_nonConstValueInInitializerFromDeferredLibrary_field_nested() {
4577 resolveWithErrors(<String>[ 4720 resolveWithErrors(<String>[
4578 r''' 4721 r'''
4579 library lib1; 4722 library lib1;
4580 const int c = 1;''', 4723 const int c = 1;''',
4581 r''' 4724 r'''
4582 library root; 4725 library root;
4583 import 'lib1.dart' deferred as a; 4726 import 'lib1.dart' deferred as a;
4584 class A { 4727 class A {
4585 final int x; 4728 final int x;
4586 const A() : x = a.c + 1; 4729 const A() : x = a.c + 1;
4587 }''' 4730 }'''
4588 ], <ErrorCode>[ 4731 ], <ErrorCode>[
4589 CompileTimeErrorCode.NON_CONSTANT_VALUE_IN_INITIALIZER_FROM_DEFERRED_LIBRA RY 4732 CompileTimeErrorCode
4733 .NON_CONSTANT_VALUE_IN_INITIALIZER_FROM_DEFERRED_LIBRARY
4590 ]); 4734 ]);
4591 } 4735 }
4592 4736
4593 void test_nonConstValueInInitializerFromDeferredLibrary_redirecting() { 4737 void test_nonConstValueInInitializerFromDeferredLibrary_redirecting() {
4594 resolveWithErrors(<String>[ 4738 resolveWithErrors(<String>[
4595 r''' 4739 r'''
4596 library lib1; 4740 library lib1;
4597 const int c = 1;''', 4741 const int c = 1;''',
4598 r''' 4742 r'''
4599 library root; 4743 library root;
4600 import 'lib1.dart' deferred as a; 4744 import 'lib1.dart' deferred as a;
4601 class A { 4745 class A {
4602 const A.named(p); 4746 const A.named(p);
4603 const A() : this.named(a.c); 4747 const A() : this.named(a.c);
4604 }''' 4748 }'''
4605 ], <ErrorCode>[ 4749 ], <ErrorCode>[
4606 CompileTimeErrorCode.NON_CONSTANT_VALUE_IN_INITIALIZER_FROM_DEFERRED_LIBRA RY 4750 CompileTimeErrorCode
4751 .NON_CONSTANT_VALUE_IN_INITIALIZER_FROM_DEFERRED_LIBRARY
4607 ]); 4752 ]);
4608 } 4753 }
4609 4754
4610 void test_nonConstValueInInitializerFromDeferredLibrary_super() { 4755 void test_nonConstValueInInitializerFromDeferredLibrary_super() {
4611 resolveWithErrors(<String>[ 4756 resolveWithErrors(<String>[
4612 r''' 4757 r'''
4613 library lib1; 4758 library lib1;
4614 const int c = 1;''', 4759 const int c = 1;''',
4615 r''' 4760 r'''
4616 library root; 4761 library root;
4617 import 'lib1.dart' deferred as a; 4762 import 'lib1.dart' deferred as a;
4618 class A { 4763 class A {
4619 const A(p); 4764 const A(p);
4620 } 4765 }
4621 class B extends A { 4766 class B extends A {
4622 const B() : super(a.c); 4767 const B() : super(a.c);
4623 }''' 4768 }'''
4624 ], <ErrorCode>[ 4769 ], <ErrorCode>[
4625 CompileTimeErrorCode.NON_CONSTANT_VALUE_IN_INITIALIZER_FROM_DEFERRED_LIBRA RY 4770 CompileTimeErrorCode
4771 .NON_CONSTANT_VALUE_IN_INITIALIZER_FROM_DEFERRED_LIBRARY
4626 ]); 4772 ]);
4627 } 4773 }
4628 4774
4629 void test_nonGenerativeConstructor_explicit() { 4775 void test_nonGenerativeConstructor_explicit() {
4630 Source source = addSource(r''' 4776 Source source = addSource(r'''
4631 class A { 4777 class A {
4632 factory A.named() {} 4778 factory A.named() => null;
4633 } 4779 }
4634 class B extends A { 4780 class B extends A {
4635 B() : super.named(); 4781 B() : super.named();
4636 }'''); 4782 }''');
4637 computeLibrarySourceErrors(source); 4783 computeLibrarySourceErrors(source);
4638 assertErrors(source, [CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR]); 4784 assertErrors(source, [CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR]);
4639 verify([source]); 4785 verify([source]);
4640 } 4786 }
4641 4787
4642 void test_nonGenerativeConstructor_implicit() { 4788 void test_nonGenerativeConstructor_implicit() {
4643 Source source = addSource(r''' 4789 Source source = addSource(r'''
4644 class A { 4790 class A {
4645 factory A() {} 4791 factory A() => null;
4646 } 4792 }
4647 class B extends A { 4793 class B extends A {
4648 B(); 4794 B();
4649 }'''); 4795 }''');
4650 computeLibrarySourceErrors(source); 4796 computeLibrarySourceErrors(source);
4651 assertErrors(source, [CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR]); 4797 assertErrors(source, [CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR]);
4652 verify([source]); 4798 verify([source]);
4653 } 4799 }
4654 4800
4655 void test_nonGenerativeConstructor_implicit2() { 4801 void test_nonGenerativeConstructor_implicit2() {
4656 Source source = addSource(r''' 4802 Source source = addSource(r'''
4657 class A { 4803 class A {
4658 factory A() {} 4804 factory A() => null;
4659 } 4805 }
4660 class B extends A { 4806 class B extends A {
4661 }'''); 4807 }''');
4662 computeLibrarySourceErrors(source); 4808 computeLibrarySourceErrors(source);
4663 assertErrors(source, [CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR]); 4809 assertErrors(source, [CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR]);
4664 verify([source]); 4810 verify([source]);
4665 } 4811 }
4666 4812
4667 void test_notEnoughRequiredArguments_const() { 4813 void test_notEnoughRequiredArguments_const() {
4668 Source source = addSource(r''' 4814 Source source = addSource(r'''
(...skipping 695 matching lines...) Expand 10 before | Expand all | Expand 10 after
5364 5510
5365 void test_recursiveInterfaceInheritanceBaseCaseExtends() { 5511 void test_recursiveInterfaceInheritanceBaseCaseExtends() {
5366 Source source = addSource("class A extends A {}"); 5512 Source source = addSource("class A extends A {}");
5367 computeLibrarySourceErrors(source); 5513 computeLibrarySourceErrors(source);
5368 assertErrors(source, [ 5514 assertErrors(source, [
5369 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_EXTENDS 5515 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_EXTENDS
5370 ]); 5516 ]);
5371 verify([source]); 5517 verify([source]);
5372 } 5518 }
5373 5519
5520 void test_recursiveInterfaceInheritanceBaseCaseExtends_abstract() {
5521 Source source = addSource(r'''
5522 class C extends C {
5523 var bar = 0;
5524 m();
5525 }
5526 ''');
5527 computeLibrarySourceErrors(source);
5528 assertErrors(source, [
5529 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_EXTENDS,
5530 StaticWarningCode.CONCRETE_CLASS_WITH_ABSTRACT_MEMBER,
5531 StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE
5532 ]);
5533 verify([source]);
5534 }
5535
5374 void test_recursiveInterfaceInheritanceBaseCaseImplements() { 5536 void test_recursiveInterfaceInheritanceBaseCaseImplements() {
5375 Source source = addSource("class A implements A {}"); 5537 Source source = addSource("class A implements A {}");
5376 computeLibrarySourceErrors(source); 5538 computeLibrarySourceErrors(source);
5377 assertErrors(source, [ 5539 assertErrors(source, [
5378 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_IMPLEMENTS 5540 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_IMPLEMENTS
5379 ]); 5541 ]);
5380 verify([source]); 5542 verify([source]);
5381 } 5543 }
5382 5544
5383 void test_recursiveInterfaceInheritanceBaseCaseImplements_typeAlias() { 5545 void test_recursiveInterfaceInheritanceBaseCaseImplements_typeAlias() {
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
5531 5693
5532 void test_referencedBeforeDeclaration_inInitializer_directly() { 5694 void test_referencedBeforeDeclaration_inInitializer_directly() {
5533 Source source = addSource(r''' 5695 Source source = addSource(r'''
5534 main() { 5696 main() {
5535 var v = v; 5697 var v = v;
5536 }'''); 5698 }''');
5537 computeLibrarySourceErrors(source); 5699 computeLibrarySourceErrors(source);
5538 assertErrors(source, [CompileTimeErrorCode.REFERENCED_BEFORE_DECLARATION]); 5700 assertErrors(source, [CompileTimeErrorCode.REFERENCED_BEFORE_DECLARATION]);
5539 } 5701 }
5540 5702
5703 void test_referencedBeforeDeclaration_type_localFunction() {
5704 Source source = addSource(r'''
5705 void testTypeRef() {
5706 String s = '';
5707 int String(int x) => x + 1;
5708 }
5709 ''');
5710 computeLibrarySourceErrors(source);
5711 assertErrors(source, [CompileTimeErrorCode.REFERENCED_BEFORE_DECLARATION]);
5712 }
5713
5714 void test_referencedBeforeDeclaration_type_localVariable() {
5715 Source source = addSource(r'''
5716 void testTypeRef() {
5717 String s = '';
5718 var String = '';
5719 }
5720 ''');
5721 computeLibrarySourceErrors(source);
5722 assertErrors(source, [CompileTimeErrorCode.REFERENCED_BEFORE_DECLARATION]);
5723 }
5724
5541 void test_rethrowOutsideCatch() { 5725 void test_rethrowOutsideCatch() {
5542 Source source = addSource(r''' 5726 Source source = addSource(r'''
5543 f() { 5727 f() {
5544 rethrow; 5728 rethrow;
5545 }'''); 5729 }''');
5546 computeLibrarySourceErrors(source); 5730 computeLibrarySourceErrors(source);
5547 assertErrors(source, [CompileTimeErrorCode.RETHROW_OUTSIDE_CATCH]); 5731 assertErrors(source, [CompileTimeErrorCode.RETHROW_OUTSIDE_CATCH]);
5548 verify([source]); 5732 verify([source]);
5549 } 5733 }
5550 5734
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
5630 } 5814 }
5631 5815
5632 void test_superInInvalidContext_factoryConstructor() { 5816 void test_superInInvalidContext_factoryConstructor() {
5633 Source source = addSource(r''' 5817 Source source = addSource(r'''
5634 class A { 5818 class A {
5635 m() {} 5819 m() {}
5636 } 5820 }
5637 class B extends A { 5821 class B extends A {
5638 factory B() { 5822 factory B() {
5639 super.m(); 5823 super.m();
5824 return null;
5640 } 5825 }
5641 }'''); 5826 }''');
5642 computeLibrarySourceErrors(source); 5827 computeLibrarySourceErrors(source);
5643 assertErrors(source, [CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT]); 5828 assertErrors(source, [CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT]);
5644 // no verify(), 'super.m' is not resolved 5829 // no verify(), 'super.m' is not resolved
5645 } 5830 }
5646 5831
5647 void test_superInInvalidContext_instanceVariableInitializer() { 5832 void test_superInInvalidContext_instanceVariableInitializer() {
5648 Source source = addSource(r''' 5833 Source source = addSource(r'''
5649 class A { 5834 class A {
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
5931 computeLibrarySourceErrors(source); 6116 computeLibrarySourceErrors(source);
5932 assertErrors(source, [CompileTimeErrorCode.URI_DOES_NOT_EXIST]); 6117 assertErrors(source, [CompileTimeErrorCode.URI_DOES_NOT_EXIST]);
5933 } 6118 }
5934 6119
5935 void test_uriDoesNotExist_import() { 6120 void test_uriDoesNotExist_import() {
5936 Source source = addSource("import 'unknown.dart';"); 6121 Source source = addSource("import 'unknown.dart';");
5937 computeLibrarySourceErrors(source); 6122 computeLibrarySourceErrors(source);
5938 assertErrors(source, [CompileTimeErrorCode.URI_DOES_NOT_EXIST]); 6123 assertErrors(source, [CompileTimeErrorCode.URI_DOES_NOT_EXIST]);
5939 } 6124 }
5940 6125
6126 void test_uriDoesNotExist_import_appears_after_deleting_target() {
6127 Source test = addSource("import 'target.dart';");
6128 Source target = addNamedSource("/target.dart", "");
6129 computeLibrarySourceErrors(test);
6130 assertErrors(test, [HintCode.UNUSED_IMPORT]);
6131
6132 // Remove the overlay in the same way as AnalysisServer.
6133 analysisContext2.setContents(target, null);
6134 ChangeSet changeSet = new ChangeSet()..removedSource(target);
6135 analysisContext2.applyChanges(changeSet);
6136
6137 computeLibrarySourceErrors(test);
6138 assertErrors(test, [CompileTimeErrorCode.URI_DOES_NOT_EXIST]);
6139 }
6140
6141 void test_uriDoesNotExist_import_disappears_when_fixed() {
6142 Source source = addSource("import 'target.dart';");
6143 computeLibrarySourceErrors(source);
6144 assertErrors(source, [CompileTimeErrorCode.URI_DOES_NOT_EXIST]);
6145
6146 // Check that the file is represented as missing.
6147 Source target =
6148 analysisContext2.getSourcesWithFullName("/target.dart").first;
6149 expect(analysisContext2.getModificationStamp(target), -1);
6150
6151 // Add an overlay in the same way as AnalysisServer.
6152 analysisContext2
6153 ..setContents(target, "")
6154 ..handleContentsChanged(target, null, "", true);
6155
6156 // Make sure the error goes away.
6157 computeLibrarySourceErrors(source);
6158 assertErrors(source, [HintCode.UNUSED_IMPORT]);
6159 }
6160
5941 void test_uriDoesNotExist_part() { 6161 void test_uriDoesNotExist_part() {
5942 Source source = addSource(r''' 6162 Source source = addSource(r'''
5943 library lib; 6163 library lib;
5944 part 'unknown.dart';'''); 6164 part 'unknown.dart';''');
5945 computeLibrarySourceErrors(source); 6165 computeLibrarySourceErrors(source);
5946 assertErrors(source, [CompileTimeErrorCode.URI_DOES_NOT_EXIST]); 6166 assertErrors(source, [CompileTimeErrorCode.URI_DOES_NOT_EXIST]);
5947 } 6167 }
5948 6168
5949 void test_uriWithInterpolation_constant() { 6169 void test_uriWithInterpolation_constant() {
5950 Source source = addSource("import 'stuff_\$platform.dart';"); 6170 Source source = addSource("import 'stuff_\$platform.dart';");
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
6179 source, [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_OPERATOR]); 6399 source, [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_OPERATOR]);
6180 verify([source]); 6400 verify([source]);
6181 reset(); 6401 reset();
6182 } 6402 }
6183 6403
6184 void _check_wrongNumberOfParametersForOperator1(String name) { 6404 void _check_wrongNumberOfParametersForOperator1(String name) {
6185 _check_wrongNumberOfParametersForOperator(name, ""); 6405 _check_wrongNumberOfParametersForOperator(name, "");
6186 _check_wrongNumberOfParametersForOperator(name, "a, b"); 6406 _check_wrongNumberOfParametersForOperator(name, "a, b");
6187 } 6407 }
6188 } 6408 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698