| OLD | NEW |
| 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 engine.compile_time_error_code_test; |
| 6 | 6 |
| 7 import 'package:analyzer/src/generated/error.dart'; | 7 import 'package:analyzer/src/generated/error.dart'; |
| 8 import 'package:analyzer/src/generated/parser.dart' show ParserErrorCode; | 8 import 'package:analyzer/src/generated/parser.dart' show ParserErrorCode; |
| 9 import 'package:analyzer/src/generated/source_io.dart'; | 9 import 'package:analyzer/src/generated/source_io.dart'; |
| 10 import 'package:unittest/unittest.dart' as _ut; | |
| 11 | 10 |
| 12 import '../reflective_tests.dart'; | 11 import '../reflective_tests.dart'; |
| 12 import '../utils.dart'; |
| 13 import 'resolver_test.dart'; | 13 import 'resolver_test.dart'; |
| 14 | 14 |
| 15 main() { | 15 main() { |
| 16 _ut.groupSep = ' | '; | 16 initializeTestEnvironment(); |
| 17 runReflectiveTests(CompileTimeErrorCodeTest); | 17 runReflectiveTests(CompileTimeErrorCodeTest); |
| 18 } | 18 } |
| 19 | 19 |
| 20 @reflectiveTest | 20 @reflectiveTest |
| 21 class CompileTimeErrorCodeTest extends ResolverTestCase { | 21 class CompileTimeErrorCodeTest extends ResolverTestCase { |
| 22 void fail_awaitInWrongContext_sync() { | 22 void fail_awaitInWrongContext_sync() { |
| 23 // This test requires better error recovery than we currently have. In | 23 // This test requires better error recovery than we currently have. In |
| 24 // particular, we need to be able to distinguish between an await expression | 24 // 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. | 25 // in the wrong context, and the use of 'await' as an identifier. |
| 26 Source source = addSource(r''' | 26 Source source = addSource(r''' |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 computeLibrarySourceErrors(source); | 200 computeLibrarySourceErrors(source); |
| 201 assertErrors(source, [CompileTimeErrorCode.ACCESS_PRIVATE_ENUM_FIELD]); | 201 assertErrors(source, [CompileTimeErrorCode.ACCESS_PRIVATE_ENUM_FIELD]); |
| 202 // Cannot verify because "_name" cannot be resolved. | 202 // Cannot verify because "_name" cannot be resolved. |
| 203 } | 203 } |
| 204 | 204 |
| 205 void test_ambiguousExport() { | 205 void test_ambiguousExport() { |
| 206 Source source = addSource(r''' | 206 Source source = addSource(r''' |
| 207 library L; | 207 library L; |
| 208 export 'lib1.dart'; | 208 export 'lib1.dart'; |
| 209 export 'lib2.dart';'''); | 209 export 'lib2.dart';'''); |
| 210 addNamedSource("/lib1.dart", r''' | 210 addNamedSource( |
| 211 "/lib1.dart", |
| 212 r''' |
| 211 library lib1; | 213 library lib1; |
| 212 class N {}'''); | 214 class N {}'''); |
| 213 addNamedSource("/lib2.dart", r''' | 215 addNamedSource( |
| 216 "/lib2.dart", |
| 217 r''' |
| 214 library lib2; | 218 library lib2; |
| 215 class N {}'''); | 219 class N {}'''); |
| 216 computeLibrarySourceErrors(source); | 220 computeLibrarySourceErrors(source); |
| 217 assertErrors(source, [CompileTimeErrorCode.AMBIGUOUS_EXPORT]); | 221 assertErrors(source, [CompileTimeErrorCode.AMBIGUOUS_EXPORT]); |
| 218 verify([source]); | 222 verify([source]); |
| 219 } | 223 } |
| 220 | 224 |
| 221 void test_async_used_as_identifier_in_annotation() { | 225 void test_async_used_as_identifier_in_annotation() { |
| 222 Source source = addSource(''' | 226 Source source = addSource(''' |
| 223 const int async = 0; | 227 const int async = 0; |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 f() async { | 468 f() async { |
| 465 return "$async"; | 469 return "$async"; |
| 466 } | 470 } |
| 467 '''); | 471 '''); |
| 468 computeLibrarySourceErrors(source); | 472 computeLibrarySourceErrors(source); |
| 469 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); | 473 assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]); |
| 470 verify([source]); | 474 verify([source]); |
| 471 } | 475 } |
| 472 | 476 |
| 473 void test_async_used_as_identifier_in_suffix() { | 477 void test_async_used_as_identifier_in_suffix() { |
| 474 addNamedSource("/lib1.dart", r''' | 478 addNamedSource( |
| 479 "/lib1.dart", |
| 480 r''' |
| 475 library lib1; | 481 library lib1; |
| 476 int async; | 482 int async; |
| 477 '''); | 483 '''); |
| 478 Source source = addSource(''' | 484 Source source = addSource(''' |
| 479 import 'lib1.dart' as l; | 485 import 'lib1.dart' as l; |
| 480 f() async { | 486 f() async { |
| 481 return l.async; | 487 return l.async; |
| 482 } | 488 } |
| 483 '''); | 489 '''); |
| 484 computeLibrarySourceErrors(source); | 490 computeLibrarySourceErrors(source); |
| (...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 948 library lib1; | 954 library lib1; |
| 949 class A { | 955 class A { |
| 950 const A(); | 956 const A(); |
| 951 }''', | 957 }''', |
| 952 r''' | 958 r''' |
| 953 library root; | 959 library root; |
| 954 import 'lib1.dart' deferred as a; | 960 import 'lib1.dart' deferred as a; |
| 955 main() { | 961 main() { |
| 956 const a.A(); | 962 const a.A(); |
| 957 }''' | 963 }''' |
| 958 ], <ErrorCode>[CompileTimeErrorCode.CONST_DEFERRED_CLASS]); | 964 ], <ErrorCode>[ |
| 965 CompileTimeErrorCode.CONST_DEFERRED_CLASS |
| 966 ]); |
| 959 } | 967 } |
| 960 | 968 |
| 961 void test_constDeferredClass_namedConstructor() { | 969 void test_constDeferredClass_namedConstructor() { |
| 962 resolveWithErrors(<String>[ | 970 resolveWithErrors(<String>[ |
| 963 r''' | 971 r''' |
| 964 library lib1; | 972 library lib1; |
| 965 class A { | 973 class A { |
| 966 const A.b(); | 974 const A.b(); |
| 967 }''', | 975 }''', |
| 968 r''' | 976 r''' |
| 969 library root; | 977 library root; |
| 970 import 'lib1.dart' deferred as a; | 978 import 'lib1.dart' deferred as a; |
| 971 main() { | 979 main() { |
| 972 const a.A.b(); | 980 const a.A.b(); |
| 973 }''' | 981 }''' |
| 974 ], <ErrorCode>[CompileTimeErrorCode.CONST_DEFERRED_CLASS]); | 982 ], <ErrorCode>[ |
| 983 CompileTimeErrorCode.CONST_DEFERRED_CLASS |
| 984 ]); |
| 975 } | 985 } |
| 976 | 986 |
| 977 void test_constEval_newInstance_constConstructor() { | 987 void test_constEval_newInstance_constConstructor() { |
| 978 Source source = addSource(r''' | 988 Source source = addSource(r''' |
| 979 class A { | 989 class A { |
| 980 const A(); | 990 const A(); |
| 981 } | 991 } |
| 982 const a = new A();'''); | 992 const a = new A();'''); |
| 983 computeLibrarySourceErrors(source); | 993 computeLibrarySourceErrors(source); |
| 984 assertErrors(source, | 994 assertErrors(source, |
| (...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1404 int A; | 1414 int A; |
| 1405 f() { | 1415 f() { |
| 1406 return const A(); | 1416 return const A(); |
| 1407 }'''); | 1417 }'''); |
| 1408 computeLibrarySourceErrors(source); | 1418 computeLibrarySourceErrors(source); |
| 1409 assertErrors(source, [CompileTimeErrorCode.CONST_WITH_NON_TYPE]); | 1419 assertErrors(source, [CompileTimeErrorCode.CONST_WITH_NON_TYPE]); |
| 1410 verify([source]); | 1420 verify([source]); |
| 1411 } | 1421 } |
| 1412 | 1422 |
| 1413 void test_constWithNonType_fromLibrary() { | 1423 void test_constWithNonType_fromLibrary() { |
| 1414 Source source1 = addNamedSource("lib.dart", ""); | 1424 Source source1 = addNamedSource("/lib.dart", ""); |
| 1415 Source source2 = addNamedSource("lib2.dart", r''' | 1425 Source source2 = addNamedSource( |
| 1426 "/lib2.dart", |
| 1427 r''' |
| 1416 import 'lib.dart' as lib; | 1428 import 'lib.dart' as lib; |
| 1417 void f() { | 1429 void f() { |
| 1418 const lib.A(); | 1430 const lib.A(); |
| 1419 }'''); | 1431 }'''); |
| 1420 computeLibrarySourceErrors(source1); | 1432 computeLibrarySourceErrors(source1); |
| 1421 computeLibrarySourceErrors(source2); | 1433 computeLibrarySourceErrors(source2); |
| 1422 assertErrors(source2, [CompileTimeErrorCode.CONST_WITH_NON_TYPE]); | 1434 assertErrors(source2, [CompileTimeErrorCode.CONST_WITH_NON_TYPE]); |
| 1423 verify([source1]); | 1435 verify([source1]); |
| 1424 } | 1436 } |
| 1425 | 1437 |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1541 }'''); | 1553 }'''); |
| 1542 computeLibrarySourceErrors(source); | 1554 computeLibrarySourceErrors(source); |
| 1543 assertErrors(source, [ | 1555 assertErrors(source, [ |
| 1544 CompileTimeErrorCode.DUPLICATE_CONSTRUCTOR_DEFAULT, | 1556 CompileTimeErrorCode.DUPLICATE_CONSTRUCTOR_DEFAULT, |
| 1545 CompileTimeErrorCode.DUPLICATE_CONSTRUCTOR_DEFAULT | 1557 CompileTimeErrorCode.DUPLICATE_CONSTRUCTOR_DEFAULT |
| 1546 ]); | 1558 ]); |
| 1547 verify([source]); | 1559 verify([source]); |
| 1548 } | 1560 } |
| 1549 | 1561 |
| 1550 void test_duplicateDefinition_acrossLibraries() { | 1562 void test_duplicateDefinition_acrossLibraries() { |
| 1551 Source librarySource = addNamedSource("/lib.dart", r''' | 1563 Source librarySource = addNamedSource( |
| 1564 "/lib.dart", |
| 1565 r''' |
| 1552 library lib; | 1566 library lib; |
| 1553 | 1567 |
| 1554 part 'a.dart'; | 1568 part 'a.dart'; |
| 1555 part 'b.dart';'''); | 1569 part 'b.dart';'''); |
| 1556 Source sourceA = addNamedSource("/a.dart", r''' | 1570 Source sourceA = addNamedSource( |
| 1571 "/a.dart", |
| 1572 r''' |
| 1557 part of lib; | 1573 part of lib; |
| 1558 | 1574 |
| 1559 class A {}'''); | 1575 class A {}'''); |
| 1560 Source sourceB = addNamedSource("/b.dart", r''' | 1576 Source sourceB = addNamedSource( |
| 1577 "/b.dart", |
| 1578 r''' |
| 1561 part of lib; | 1579 part of lib; |
| 1562 | 1580 |
| 1563 class A {}'''); | 1581 class A {}'''); |
| 1564 computeLibrarySourceErrors(librarySource); | 1582 computeLibrarySourceErrors(librarySource); |
| 1565 assertErrors(sourceB, [CompileTimeErrorCode.DUPLICATE_DEFINITION]); | 1583 assertErrors(sourceB, [CompileTimeErrorCode.DUPLICATE_DEFINITION]); |
| 1566 verify([librarySource, sourceA, sourceB]); | 1584 verify([librarySource, sourceA, sourceB]); |
| 1567 } | 1585 } |
| 1568 | 1586 |
| 1569 void test_duplicateDefinition_catch() { | 1587 void test_duplicateDefinition_catch() { |
| 1570 Source source = addSource(r''' | 1588 Source source = addSource(r''' |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1823 | 1841 |
| 1824 void test_extendsDeferredClass() { | 1842 void test_extendsDeferredClass() { |
| 1825 resolveWithErrors(<String>[ | 1843 resolveWithErrors(<String>[ |
| 1826 r''' | 1844 r''' |
| 1827 library lib1; | 1845 library lib1; |
| 1828 class A {}''', | 1846 class A {}''', |
| 1829 r''' | 1847 r''' |
| 1830 library root; | 1848 library root; |
| 1831 import 'lib1.dart' deferred as a; | 1849 import 'lib1.dart' deferred as a; |
| 1832 class B extends a.A {}''' | 1850 class B extends a.A {}''' |
| 1833 ], <ErrorCode>[CompileTimeErrorCode.EXTENDS_DEFERRED_CLASS]); | 1851 ], <ErrorCode>[ |
| 1852 CompileTimeErrorCode.EXTENDS_DEFERRED_CLASS |
| 1853 ]); |
| 1834 } | 1854 } |
| 1835 | 1855 |
| 1836 void test_extendsDeferredClass_classTypeAlias() { | 1856 void test_extendsDeferredClass_classTypeAlias() { |
| 1837 resolveWithErrors(<String>[ | 1857 resolveWithErrors(<String>[ |
| 1838 r''' | 1858 r''' |
| 1839 library lib1; | 1859 library lib1; |
| 1840 class A {}''', | 1860 class A {}''', |
| 1841 r''' | 1861 r''' |
| 1842 library root; | 1862 library root; |
| 1843 import 'lib1.dart' deferred as a; | 1863 import 'lib1.dart' deferred as a; |
| 1844 class M {} | 1864 class M {} |
| 1845 class C = a.A with M;''' | 1865 class C = a.A with M;''' |
| 1846 ], <ErrorCode>[CompileTimeErrorCode.EXTENDS_DEFERRED_CLASS]); | 1866 ], <ErrorCode>[ |
| 1867 CompileTimeErrorCode.EXTENDS_DEFERRED_CLASS |
| 1868 ]); |
| 1847 } | 1869 } |
| 1848 | 1870 |
| 1849 void test_extendsDisallowedClass_class_bool() { | 1871 void test_extendsDisallowedClass_class_bool() { |
| 1850 Source source = addSource("class A extends bool {}"); | 1872 Source source = addSource("class A extends bool {}"); |
| 1851 computeLibrarySourceErrors(source); | 1873 computeLibrarySourceErrors(source); |
| 1852 assertErrors(source, [ | 1874 assertErrors(source, [ |
| 1853 CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS, | 1875 CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS, |
| 1854 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT | 1876 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT |
| 1855 ]); | 1877 ]); |
| 1856 verify([source]); | 1878 verify([source]); |
| (...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2255 | 2277 |
| 2256 void test_implementsDeferredClass() { | 2278 void test_implementsDeferredClass() { |
| 2257 resolveWithErrors(<String>[ | 2279 resolveWithErrors(<String>[ |
| 2258 r''' | 2280 r''' |
| 2259 library lib1; | 2281 library lib1; |
| 2260 class A {}''', | 2282 class A {}''', |
| 2261 r''' | 2283 r''' |
| 2262 library root; | 2284 library root; |
| 2263 import 'lib1.dart' deferred as a; | 2285 import 'lib1.dart' deferred as a; |
| 2264 class B implements a.A {}''' | 2286 class B implements a.A {}''' |
| 2265 ], <ErrorCode>[CompileTimeErrorCode.IMPLEMENTS_DEFERRED_CLASS]); | 2287 ], <ErrorCode>[ |
| 2288 CompileTimeErrorCode.IMPLEMENTS_DEFERRED_CLASS |
| 2289 ]); |
| 2266 } | 2290 } |
| 2267 | 2291 |
| 2268 void test_implementsDeferredClass_classTypeAlias() { | 2292 void test_implementsDeferredClass_classTypeAlias() { |
| 2269 resolveWithErrors(<String>[ | 2293 resolveWithErrors(<String>[ |
| 2270 r''' | 2294 r''' |
| 2271 library lib1; | 2295 library lib1; |
| 2272 class A {}''', | 2296 class A {}''', |
| 2273 r''' | 2297 r''' |
| 2274 library root; | 2298 library root; |
| 2275 import 'lib1.dart' deferred as a; | 2299 import 'lib1.dart' deferred as a; |
| 2276 class B {} | 2300 class B {} |
| 2277 class M {} | 2301 class M {} |
| 2278 class C = B with M implements a.A;''' | 2302 class C = B with M implements a.A;''' |
| 2279 ], <ErrorCode>[CompileTimeErrorCode.IMPLEMENTS_DEFERRED_CLASS]); | 2303 ], <ErrorCode>[ |
| 2304 CompileTimeErrorCode.IMPLEMENTS_DEFERRED_CLASS |
| 2305 ]); |
| 2280 } | 2306 } |
| 2281 | 2307 |
| 2282 void test_implementsDisallowedClass_class_bool() { | 2308 void test_implementsDisallowedClass_class_bool() { |
| 2283 Source source = addSource("class A implements bool {}"); | 2309 Source source = addSource("class A implements bool {}"); |
| 2284 computeLibrarySourceErrors(source); | 2310 computeLibrarySourceErrors(source); |
| 2285 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]); | 2311 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS]); |
| 2286 verify([source]); | 2312 verify([source]); |
| 2287 } | 2313 } |
| 2288 | 2314 |
| 2289 void test_implementsDisallowedClass_class_double() { | 2315 void test_implementsDisallowedClass_class_double() { |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2557 } | 2583 } |
| 2558 | 2584 |
| 2559 void test_importInternalLibrary() { | 2585 void test_importInternalLibrary() { |
| 2560 Source source = addSource("import 'dart:_interceptors';"); | 2586 Source source = addSource("import 'dart:_interceptors';"); |
| 2561 computeLibrarySourceErrors(source); | 2587 computeLibrarySourceErrors(source); |
| 2562 // Note, in these error cases we may generate an UNUSED_IMPORT hint, while | 2588 // Note, in these error cases we may generate an UNUSED_IMPORT hint, while |
| 2563 // we could prevent the hint from being generated by testing the import | 2589 // we could prevent the hint from being generated by testing the import |
| 2564 // directive for the error, this is such a minor corner case that we don't | 2590 // directive for the error, this is such a minor corner case that we don't |
| 2565 // think we should add the additional computation time to figure out such | 2591 // think we should add the additional computation time to figure out such |
| 2566 // cases. | 2592 // cases. |
| 2567 assertErrors(source, [ | 2593 assertErrors(source, |
| 2568 CompileTimeErrorCode.IMPORT_INTERNAL_LIBRARY, | 2594 [CompileTimeErrorCode.IMPORT_INTERNAL_LIBRARY, HintCode.UNUSED_IMPORT]); |
| 2569 HintCode.UNUSED_IMPORT | |
| 2570 ]); | |
| 2571 verify([source]); | 2595 verify([source]); |
| 2572 } | 2596 } |
| 2573 | 2597 |
| 2574 void test_importInternalLibrary_js_helper() { | 2598 void test_importInternalLibrary_js_helper() { |
| 2575 Source source = addSource("import 'dart:_js_helper';"); | 2599 Source source = addSource("import 'dart:_js_helper';"); |
| 2576 computeLibrarySourceErrors(source); | 2600 computeLibrarySourceErrors(source); |
| 2577 // Note, in these error cases we may generate an UNUSED_IMPORT hint, while | 2601 // Note, in these error cases we may generate an UNUSED_IMPORT hint, while |
| 2578 // we could prevent the hint from being generated by testing the import | 2602 // we could prevent the hint from being generated by testing the import |
| 2579 // directive for the error, this is such a minor corner case that we don't | 2603 // directive for the error, this is such a minor corner case that we don't |
| 2580 // think we should add the additional computation time to figure out such | 2604 // think we should add the additional computation time to figure out such |
| 2581 // cases. | 2605 // cases. |
| 2582 assertErrors(source, [ | 2606 assertErrors(source, |
| 2583 CompileTimeErrorCode.IMPORT_INTERNAL_LIBRARY, | 2607 [CompileTimeErrorCode.IMPORT_INTERNAL_LIBRARY, HintCode.UNUSED_IMPORT]); |
| 2584 HintCode.UNUSED_IMPORT | |
| 2585 ]); | |
| 2586 verify([source]); | 2608 verify([source]); |
| 2587 } | 2609 } |
| 2588 | 2610 |
| 2589 void test_importOfNonLibrary() { | 2611 void test_importOfNonLibrary() { |
| 2590 Source source = addSource(r''' | 2612 Source source = addSource(r''' |
| 2591 library lib; | 2613 library lib; |
| 2592 import 'part.dart'; | 2614 import 'part.dart'; |
| 2593 A a;'''); | 2615 A a;'''); |
| 2594 addNamedSource("/part.dart", r''' | 2616 addNamedSource( |
| 2617 "/part.dart", |
| 2618 r''' |
| 2595 part of lib; | 2619 part of lib; |
| 2596 class A{}'''); | 2620 class A{}'''); |
| 2597 computeLibrarySourceErrors(source); | 2621 computeLibrarySourceErrors(source); |
| 2598 assertErrors(source, [CompileTimeErrorCode.IMPORT_OF_NON_LIBRARY]); | 2622 assertErrors(source, [CompileTimeErrorCode.IMPORT_OF_NON_LIBRARY]); |
| 2599 verify([source]); | 2623 verify([source]); |
| 2600 } | 2624 } |
| 2601 | 2625 |
| 2602 void test_inconsistentCaseExpressionTypes() { | 2626 void test_inconsistentCaseExpressionTypes() { |
| 2603 Source source = addSource(r''' | 2627 Source source = addSource(r''' |
| 2604 f(var p) { | 2628 f(var p) { |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2858 get V => 0; | 2882 get V => 0; |
| 2859 @V | 2883 @V |
| 2860 main() { | 2884 main() { |
| 2861 }'''); | 2885 }'''); |
| 2862 computeLibrarySourceErrors(source); | 2886 computeLibrarySourceErrors(source); |
| 2863 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]); | 2887 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]); |
| 2864 verify([source]); | 2888 verify([source]); |
| 2865 } | 2889 } |
| 2866 | 2890 |
| 2867 void test_invalidAnnotation_importWithPrefix_getter() { | 2891 void test_invalidAnnotation_importWithPrefix_getter() { |
| 2868 addNamedSource("/lib.dart", r''' | 2892 addNamedSource( |
| 2893 "/lib.dart", |
| 2894 r''' |
| 2869 library lib; | 2895 library lib; |
| 2870 get V => 0;'''); | 2896 get V => 0;'''); |
| 2871 Source source = addSource(r''' | 2897 Source source = addSource(r''' |
| 2872 import 'lib.dart' as p; | 2898 import 'lib.dart' as p; |
| 2873 @p.V | 2899 @p.V |
| 2874 main() { | 2900 main() { |
| 2875 }'''); | 2901 }'''); |
| 2876 computeLibrarySourceErrors(source); | 2902 computeLibrarySourceErrors(source); |
| 2877 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]); | 2903 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]); |
| 2878 verify([source]); | 2904 verify([source]); |
| 2879 } | 2905 } |
| 2880 | 2906 |
| 2881 void test_invalidAnnotation_importWithPrefix_notConstantVariable() { | 2907 void test_invalidAnnotation_importWithPrefix_notConstantVariable() { |
| 2882 addNamedSource("/lib.dart", r''' | 2908 addNamedSource( |
| 2909 "/lib.dart", |
| 2910 r''' |
| 2883 library lib; | 2911 library lib; |
| 2884 final V = 0;'''); | 2912 final V = 0;'''); |
| 2885 Source source = addSource(r''' | 2913 Source source = addSource(r''' |
| 2886 import 'lib.dart' as p; | 2914 import 'lib.dart' as p; |
| 2887 @p.V | 2915 @p.V |
| 2888 main() { | 2916 main() { |
| 2889 }'''); | 2917 }'''); |
| 2890 computeLibrarySourceErrors(source); | 2918 computeLibrarySourceErrors(source); |
| 2891 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]); | 2919 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]); |
| 2892 verify([source]); | 2920 verify([source]); |
| 2893 } | 2921 } |
| 2894 | 2922 |
| 2895 void test_invalidAnnotation_importWithPrefix_notVariableOrConstructorInvocatio
n() { | 2923 void test_invalidAnnotation_importWithPrefix_notVariableOrConstructorInvocatio
n() { |
| 2896 addNamedSource("/lib.dart", r''' | 2924 addNamedSource( |
| 2925 "/lib.dart", |
| 2926 r''' |
| 2897 library lib; | 2927 library lib; |
| 2898 typedef V();'''); | 2928 typedef V();'''); |
| 2899 Source source = addSource(r''' | 2929 Source source = addSource(r''' |
| 2900 import 'lib.dart' as p; | 2930 import 'lib.dart' as p; |
| 2901 @p.V | 2931 @p.V |
| 2902 main() { | 2932 main() { |
| 2903 }'''); | 2933 }'''); |
| 2904 computeLibrarySourceErrors(source); | 2934 computeLibrarySourceErrors(source); |
| 2905 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]); | 2935 assertErrors(source, [CompileTimeErrorCode.INVALID_ANNOTATION]); |
| 2906 verify([source]); | 2936 verify([source]); |
| (...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3457 | 3487 |
| 3458 void test_mixinDeferredClass() { | 3488 void test_mixinDeferredClass() { |
| 3459 resolveWithErrors(<String>[ | 3489 resolveWithErrors(<String>[ |
| 3460 r''' | 3490 r''' |
| 3461 library lib1; | 3491 library lib1; |
| 3462 class A {}''', | 3492 class A {}''', |
| 3463 r''' | 3493 r''' |
| 3464 library root; | 3494 library root; |
| 3465 import 'lib1.dart' deferred as a; | 3495 import 'lib1.dart' deferred as a; |
| 3466 class B extends Object with a.A {}''' | 3496 class B extends Object with a.A {}''' |
| 3467 ], <ErrorCode>[CompileTimeErrorCode.MIXIN_DEFERRED_CLASS]); | 3497 ], <ErrorCode>[ |
| 3498 CompileTimeErrorCode.MIXIN_DEFERRED_CLASS |
| 3499 ]); |
| 3468 } | 3500 } |
| 3469 | 3501 |
| 3470 void test_mixinDeferredClass_classTypeAlias() { | 3502 void test_mixinDeferredClass_classTypeAlias() { |
| 3471 resolveWithErrors(<String>[ | 3503 resolveWithErrors(<String>[ |
| 3472 r''' | 3504 r''' |
| 3473 library lib1; | 3505 library lib1; |
| 3474 class A {}''', | 3506 class A {}''', |
| 3475 r''' | 3507 r''' |
| 3476 library root; | 3508 library root; |
| 3477 import 'lib1.dart' deferred as a; | 3509 import 'lib1.dart' deferred as a; |
| 3478 class B {} | 3510 class B {} |
| 3479 class C = B with a.A;''' | 3511 class C = B with a.A;''' |
| 3480 ], <ErrorCode>[CompileTimeErrorCode.MIXIN_DEFERRED_CLASS]); | 3512 ], <ErrorCode>[ |
| 3513 CompileTimeErrorCode.MIXIN_DEFERRED_CLASS |
| 3514 ]); |
| 3481 } | 3515 } |
| 3482 | 3516 |
| 3483 void test_mixinHasNoConstructors_mixinApp() { | 3517 void test_mixinHasNoConstructors_mixinApp() { |
| 3484 Source source = addSource(r''' | 3518 Source source = addSource(r''' |
| 3485 class B { | 3519 class B { |
| 3486 B({x}); | 3520 B({x}); |
| 3487 } | 3521 } |
| 3488 class M {} | 3522 class M {} |
| 3489 class C = B with M; | 3523 class C = B with M; |
| 3490 '''); | 3524 '''); |
| (...skipping 1258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4749 p = 1; | 4783 p = 1; |
| 4750 } | 4784 } |
| 4751 '''); | 4785 '''); |
| 4752 computeLibrarySourceErrors(source); | 4786 computeLibrarySourceErrors(source); |
| 4753 assertErrors( | 4787 assertErrors( |
| 4754 source, [CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT]); | 4788 source, [CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT]); |
| 4755 verify([source]); | 4789 verify([source]); |
| 4756 } | 4790 } |
| 4757 | 4791 |
| 4758 void test_prefix_conditionalPropertyAccess_call() { | 4792 void test_prefix_conditionalPropertyAccess_call() { |
| 4759 addNamedSource('/lib.dart', ''' | 4793 addNamedSource( |
| 4794 '/lib.dart', |
| 4795 ''' |
| 4760 library lib; | 4796 library lib; |
| 4761 g() {} | 4797 g() {} |
| 4762 '''); | 4798 '''); |
| 4763 Source source = addSource(''' | 4799 Source source = addSource(''' |
| 4764 import 'lib.dart' as p; | 4800 import 'lib.dart' as p; |
| 4765 f() { | 4801 f() { |
| 4766 p?.g(); | 4802 p?.g(); |
| 4767 } | 4803 } |
| 4768 '''); | 4804 '''); |
| 4769 computeLibrarySourceErrors(source); | 4805 computeLibrarySourceErrors(source); |
| 4770 assertErrors( | 4806 assertErrors( |
| 4771 source, [CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT]); | 4807 source, [CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT]); |
| 4772 verify([source]); | 4808 verify([source]); |
| 4773 } | 4809 } |
| 4774 | 4810 |
| 4775 void test_prefix_conditionalPropertyAccess_call_loadLibrary() { | 4811 void test_prefix_conditionalPropertyAccess_call_loadLibrary() { |
| 4776 addNamedSource('/lib.dart', ''' | 4812 addNamedSource( |
| 4813 '/lib.dart', |
| 4814 ''' |
| 4777 library lib; | 4815 library lib; |
| 4778 '''); | 4816 '''); |
| 4779 Source source = addSource(''' | 4817 Source source = addSource(''' |
| 4780 import 'lib.dart' deferred as p; | 4818 import 'lib.dart' deferred as p; |
| 4781 f() { | 4819 f() { |
| 4782 p?.loadLibrary(); | 4820 p?.loadLibrary(); |
| 4783 } | 4821 } |
| 4784 '''); | 4822 '''); |
| 4785 computeLibrarySourceErrors(source); | 4823 computeLibrarySourceErrors(source); |
| 4786 assertErrors( | 4824 assertErrors( |
| 4787 source, [CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT]); | 4825 source, [CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT]); |
| 4788 verify([source]); | 4826 verify([source]); |
| 4789 } | 4827 } |
| 4790 | 4828 |
| 4791 void test_prefix_conditionalPropertyAccess_get() { | 4829 void test_prefix_conditionalPropertyAccess_get() { |
| 4792 addNamedSource('/lib.dart', ''' | 4830 addNamedSource( |
| 4831 '/lib.dart', |
| 4832 ''' |
| 4793 library lib; | 4833 library lib; |
| 4794 var x; | 4834 var x; |
| 4795 '''); | 4835 '''); |
| 4796 Source source = addSource(''' | 4836 Source source = addSource(''' |
| 4797 import 'lib.dart' as p; | 4837 import 'lib.dart' as p; |
| 4798 f() { | 4838 f() { |
| 4799 return p?.x; | 4839 return p?.x; |
| 4800 } | 4840 } |
| 4801 '''); | 4841 '''); |
| 4802 computeLibrarySourceErrors(source); | 4842 computeLibrarySourceErrors(source); |
| 4803 assertErrors( | 4843 assertErrors( |
| 4804 source, [CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT]); | 4844 source, [CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT]); |
| 4805 verify([source]); | 4845 verify([source]); |
| 4806 } | 4846 } |
| 4807 | 4847 |
| 4808 void test_prefix_conditionalPropertyAccess_get_loadLibrary() { | 4848 void test_prefix_conditionalPropertyAccess_get_loadLibrary() { |
| 4809 addNamedSource('/lib.dart', ''' | 4849 addNamedSource( |
| 4850 '/lib.dart', |
| 4851 ''' |
| 4810 library lib; | 4852 library lib; |
| 4811 '''); | 4853 '''); |
| 4812 Source source = addSource(''' | 4854 Source source = addSource(''' |
| 4813 import 'lib.dart' deferred as p; | 4855 import 'lib.dart' deferred as p; |
| 4814 f() { | 4856 f() { |
| 4815 return p?.loadLibrary; | 4857 return p?.loadLibrary; |
| 4816 } | 4858 } |
| 4817 '''); | 4859 '''); |
| 4818 computeLibrarySourceErrors(source); | 4860 computeLibrarySourceErrors(source); |
| 4819 assertErrors( | 4861 assertErrors( |
| 4820 source, [CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT]); | 4862 source, [CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT]); |
| 4821 verify([source]); | 4863 verify([source]); |
| 4822 } | 4864 } |
| 4823 | 4865 |
| 4824 void test_prefix_conditionalPropertyAccess_set() { | 4866 void test_prefix_conditionalPropertyAccess_set() { |
| 4825 addNamedSource('/lib.dart', ''' | 4867 addNamedSource( |
| 4868 '/lib.dart', |
| 4869 ''' |
| 4826 library lib; | 4870 library lib; |
| 4827 var x; | 4871 var x; |
| 4828 '''); | 4872 '''); |
| 4829 Source source = addSource(''' | 4873 Source source = addSource(''' |
| 4830 import 'lib.dart' as p; | 4874 import 'lib.dart' as p; |
| 4831 f() { | 4875 f() { |
| 4832 p?.x = null; | 4876 p?.x = null; |
| 4833 } | 4877 } |
| 4834 '''); | 4878 '''); |
| 4835 computeLibrarySourceErrors(source); | 4879 computeLibrarySourceErrors(source); |
| 4836 assertErrors( | 4880 assertErrors( |
| 4837 source, [CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT]); | 4881 source, [CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT]); |
| 4838 verify([source]); | 4882 verify([source]); |
| 4839 } | 4883 } |
| 4840 | 4884 |
| 4841 void test_prefix_conditionalPropertyAccess_set_loadLibrary() { | 4885 void test_prefix_conditionalPropertyAccess_set_loadLibrary() { |
| 4842 addNamedSource('/lib.dart', ''' | 4886 addNamedSource( |
| 4887 '/lib.dart', |
| 4888 ''' |
| 4843 library lib; | 4889 library lib; |
| 4844 '''); | 4890 '''); |
| 4845 Source source = addSource(''' | 4891 Source source = addSource(''' |
| 4846 import 'lib.dart' deferred as p; | 4892 import 'lib.dart' deferred as p; |
| 4847 f() { | 4893 f() { |
| 4848 p?.loadLibrary = null; | 4894 p?.loadLibrary = null; |
| 4849 } | 4895 } |
| 4850 '''); | 4896 '''); |
| 4851 computeLibrarySourceErrors(source); | 4897 computeLibrarySourceErrors(source); |
| 4852 assertErrors( | 4898 assertErrors( |
| (...skipping 25 matching lines...) Expand all Loading... |
| 4878 p(); | 4924 p(); |
| 4879 } | 4925 } |
| 4880 '''); | 4926 '''); |
| 4881 computeLibrarySourceErrors(source); | 4927 computeLibrarySourceErrors(source); |
| 4882 assertErrors( | 4928 assertErrors( |
| 4883 source, [CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT]); | 4929 source, [CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT]); |
| 4884 verify([source]); | 4930 verify([source]); |
| 4885 } | 4931 } |
| 4886 | 4932 |
| 4887 void test_prefixCollidesWithTopLevelMembers_functionTypeAlias() { | 4933 void test_prefixCollidesWithTopLevelMembers_functionTypeAlias() { |
| 4888 addNamedSource("/lib.dart", r''' | 4934 addNamedSource( |
| 4935 "/lib.dart", |
| 4936 r''' |
| 4889 library lib; | 4937 library lib; |
| 4890 class A{}'''); | 4938 class A{}'''); |
| 4891 Source source = addSource(r''' | 4939 Source source = addSource(r''' |
| 4892 import 'lib.dart' as p; | 4940 import 'lib.dart' as p; |
| 4893 typedef p(); | 4941 typedef p(); |
| 4894 p.A a;'''); | 4942 p.A a;'''); |
| 4895 computeLibrarySourceErrors(source); | 4943 computeLibrarySourceErrors(source); |
| 4896 assertErrors( | 4944 assertErrors( |
| 4897 source, [CompileTimeErrorCode.PREFIX_COLLIDES_WITH_TOP_LEVEL_MEMBER]); | 4945 source, [CompileTimeErrorCode.PREFIX_COLLIDES_WITH_TOP_LEVEL_MEMBER]); |
| 4898 verify([source]); | 4946 verify([source]); |
| 4899 } | 4947 } |
| 4900 | 4948 |
| 4901 void test_prefixCollidesWithTopLevelMembers_topLevelFunction() { | 4949 void test_prefixCollidesWithTopLevelMembers_topLevelFunction() { |
| 4902 addNamedSource("/lib.dart", r''' | 4950 addNamedSource( |
| 4951 "/lib.dart", |
| 4952 r''' |
| 4903 library lib; | 4953 library lib; |
| 4904 class A{}'''); | 4954 class A{}'''); |
| 4905 Source source = addSource(r''' | 4955 Source source = addSource(r''' |
| 4906 import 'lib.dart' as p; | 4956 import 'lib.dart' as p; |
| 4907 p() {} | 4957 p() {} |
| 4908 p.A a;'''); | 4958 p.A a;'''); |
| 4909 computeLibrarySourceErrors(source); | 4959 computeLibrarySourceErrors(source); |
| 4910 assertErrors( | 4960 assertErrors( |
| 4911 source, [CompileTimeErrorCode.PREFIX_COLLIDES_WITH_TOP_LEVEL_MEMBER]); | 4961 source, [CompileTimeErrorCode.PREFIX_COLLIDES_WITH_TOP_LEVEL_MEMBER]); |
| 4912 verify([source]); | 4962 verify([source]); |
| 4913 } | 4963 } |
| 4914 | 4964 |
| 4915 void test_prefixCollidesWithTopLevelMembers_topLevelVariable() { | 4965 void test_prefixCollidesWithTopLevelMembers_topLevelVariable() { |
| 4916 addNamedSource("/lib.dart", r''' | 4966 addNamedSource( |
| 4967 "/lib.dart", |
| 4968 r''' |
| 4917 library lib; | 4969 library lib; |
| 4918 class A{}'''); | 4970 class A{}'''); |
| 4919 Source source = addSource(r''' | 4971 Source source = addSource(r''' |
| 4920 import 'lib.dart' as p; | 4972 import 'lib.dart' as p; |
| 4921 var p = null; | 4973 var p = null; |
| 4922 p.A a;'''); | 4974 p.A a;'''); |
| 4923 computeLibrarySourceErrors(source); | 4975 computeLibrarySourceErrors(source); |
| 4924 assertErrors( | 4976 assertErrors( |
| 4925 source, [CompileTimeErrorCode.PREFIX_COLLIDES_WITH_TOP_LEVEL_MEMBER]); | 4977 source, [CompileTimeErrorCode.PREFIX_COLLIDES_WITH_TOP_LEVEL_MEMBER]); |
| 4926 verify([source]); | 4978 verify([source]); |
| 4927 } | 4979 } |
| 4928 | 4980 |
| 4929 void test_prefixCollidesWithTopLevelMembers_type() { | 4981 void test_prefixCollidesWithTopLevelMembers_type() { |
| 4930 addNamedSource("/lib.dart", r''' | 4982 addNamedSource( |
| 4983 "/lib.dart", |
| 4984 r''' |
| 4931 library lib; | 4985 library lib; |
| 4932 class A{}'''); | 4986 class A{}'''); |
| 4933 Source source = addSource(r''' | 4987 Source source = addSource(r''' |
| 4934 import 'lib.dart' as p; | 4988 import 'lib.dart' as p; |
| 4935 class p {} | 4989 class p {} |
| 4936 p.A a;'''); | 4990 p.A a;'''); |
| 4937 computeLibrarySourceErrors(source); | 4991 computeLibrarySourceErrors(source); |
| 4938 assertErrors( | 4992 assertErrors( |
| 4939 source, [CompileTimeErrorCode.PREFIX_COLLIDES_WITH_TOP_LEVEL_MEMBER]); | 4993 source, [CompileTimeErrorCode.PREFIX_COLLIDES_WITH_TOP_LEVEL_MEMBER]); |
| 4940 verify([source]); | 4994 verify([source]); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 4962 p += 1; | 5016 p += 1; |
| 4963 } | 5017 } |
| 4964 '''); | 5018 '''); |
| 4965 computeLibrarySourceErrors(source); | 5019 computeLibrarySourceErrors(source); |
| 4966 assertErrors( | 5020 assertErrors( |
| 4967 source, [CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT]); | 5021 source, [CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT]); |
| 4968 verify([source]); | 5022 verify([source]); |
| 4969 } | 5023 } |
| 4970 | 5024 |
| 4971 void test_prefixNotFollowedByDot_conditionalMethodInvocation() { | 5025 void test_prefixNotFollowedByDot_conditionalMethodInvocation() { |
| 4972 addNamedSource('/lib.dart', ''' | 5026 addNamedSource( |
| 5027 '/lib.dart', |
| 5028 ''' |
| 4973 library lib; | 5029 library lib; |
| 4974 g() {} | 5030 g() {} |
| 4975 '''); | 5031 '''); |
| 4976 Source source = addSource(''' | 5032 Source source = addSource(''' |
| 4977 import 'lib.dart' as p; | 5033 import 'lib.dart' as p; |
| 4978 f() { | 5034 f() { |
| 4979 p?.g(); | 5035 p?.g(); |
| 4980 } | 5036 } |
| 4981 '''); | 5037 '''); |
| 4982 computeLibrarySourceErrors(source); | 5038 computeLibrarySourceErrors(source); |
| (...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5540 library lib1; | 5596 library lib1; |
| 5541 f1() {}''', | 5597 f1() {}''', |
| 5542 r''' | 5598 r''' |
| 5543 library lib2; | 5599 library lib2; |
| 5544 f2() {}''', | 5600 f2() {}''', |
| 5545 r''' | 5601 r''' |
| 5546 library root; | 5602 library root; |
| 5547 import 'lib1.dart' deferred as lib; | 5603 import 'lib1.dart' deferred as lib; |
| 5548 import 'lib2.dart' as lib; | 5604 import 'lib2.dart' as lib; |
| 5549 main() { lib.f1(); lib.f2(); }''' | 5605 main() { lib.f1(); lib.f2(); }''' |
| 5550 ], <ErrorCode>[CompileTimeErrorCode.SHARED_DEFERRED_PREFIX]); | 5606 ], <ErrorCode>[ |
| 5607 CompileTimeErrorCode.SHARED_DEFERRED_PREFIX |
| 5608 ]); |
| 5551 } | 5609 } |
| 5552 | 5610 |
| 5553 void test_superInInvalidContext_binaryExpression() { | 5611 void test_superInInvalidContext_binaryExpression() { |
| 5554 Source source = addSource("var v = super + 0;"); | 5612 Source source = addSource("var v = super + 0;"); |
| 5555 computeLibrarySourceErrors(source); | 5613 computeLibrarySourceErrors(source); |
| 5556 assertErrors(source, [CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT]); | 5614 assertErrors(source, [CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT]); |
| 5557 // no verify(), 'super.v' is not resolved | 5615 // no verify(), 'super.v' is not resolved |
| 5558 } | 5616 } |
| 5559 | 5617 |
| 5560 void test_superInInvalidContext_constructorFieldInitializer() { | 5618 void test_superInInvalidContext_constructorFieldInitializer() { |
| (...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6121 source, [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_OPERATOR]); | 6179 source, [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_OPERATOR]); |
| 6122 verify([source]); | 6180 verify([source]); |
| 6123 reset(); | 6181 reset(); |
| 6124 } | 6182 } |
| 6125 | 6183 |
| 6126 void _check_wrongNumberOfParametersForOperator1(String name) { | 6184 void _check_wrongNumberOfParametersForOperator1(String name) { |
| 6127 _check_wrongNumberOfParametersForOperator(name, ""); | 6185 _check_wrongNumberOfParametersForOperator(name, ""); |
| 6128 _check_wrongNumberOfParametersForOperator(name, "a, b"); | 6186 _check_wrongNumberOfParametersForOperator(name, "a, b"); |
| 6129 } | 6187 } |
| 6130 } | 6188 } |
| OLD | NEW |