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.static_type_warning_code_test; | 5 library engine.static_type_warning_code_test; |
6 | 6 |
7 import 'package:analyzer/src/generated/engine.dart'; | 7 import 'package:analyzer/src/generated/engine.dart'; |
8 import 'package:analyzer/src/generated/error.dart'; | 8 import 'package:analyzer/src/generated/error.dart'; |
9 import 'package:analyzer/src/generated/source_io.dart'; | 9 import 'package:analyzer/src/generated/source_io.dart'; |
10 import 'package:unittest/unittest.dart'; | 10 import 'package:unittest/unittest.dart'; |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 Source source = addSource(''' | 378 Source source = addSource(''' |
379 main() { | 379 main() { |
380 String x = (() => 5)(); | 380 String x = (() => 5)(); |
381 }'''); | 381 }'''); |
382 computeLibrarySourceErrors(source); | 382 computeLibrarySourceErrors(source); |
383 assertErrors(source, [StaticTypeWarningCode.INVALID_ASSIGNMENT]); | 383 assertErrors(source, [StaticTypeWarningCode.INVALID_ASSIGNMENT]); |
384 verify([source]); | 384 verify([source]); |
385 } | 385 } |
386 | 386 |
387 void test_invalidAssignment_ifNullAssignment() { | 387 void test_invalidAssignment_ifNullAssignment() { |
388 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); | |
389 options.enableNullAwareOperators = true; | |
390 resetWithOptions(options); | |
391 Source source = addSource(''' | 388 Source source = addSource(''' |
392 void f(int i) { | 389 void f(int i) { |
393 double d; | 390 double d; |
394 d ??= i; | 391 d ??= i; |
395 } | 392 } |
396 '''); | 393 '''); |
397 computeLibrarySourceErrors(source); | 394 computeLibrarySourceErrors(source); |
398 assertErrors(source, [StaticTypeWarningCode.INVALID_ASSIGNMENT]); | 395 assertErrors(source, [StaticTypeWarningCode.INVALID_ASSIGNMENT]); |
399 verify([source]); | 396 verify([source]); |
400 } | 397 } |
(...skipping 989 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1390 Source source = addSource(r''' | 1387 Source source = addSource(r''' |
1391 class A {} | 1388 class A {} |
1392 var a = A.B;'''); | 1389 var a = A.B;'''); |
1393 computeLibrarySourceErrors(source); | 1390 computeLibrarySourceErrors(source); |
1394 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_GETTER]); | 1391 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_GETTER]); |
1395 } | 1392 } |
1396 | 1393 |
1397 void test_undefinedGetter_static_conditionalAccess() { | 1394 void test_undefinedGetter_static_conditionalAccess() { |
1398 // The conditional access operator '?.' cannot be used to access static | 1395 // The conditional access operator '?.' cannot be used to access static |
1399 // fields. | 1396 // fields. |
1400 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); | |
1401 options.enableNullAwareOperators = true; | |
1402 resetWithOptions(options); | |
1403 Source source = addSource(''' | 1397 Source source = addSource(''' |
1404 class A { | 1398 class A { |
1405 static var x; | 1399 static var x; |
1406 } | 1400 } |
1407 var a = A?.x; | 1401 var a = A?.x; |
1408 '''); | 1402 '''); |
1409 computeLibrarySourceErrors(source); | 1403 computeLibrarySourceErrors(source); |
1410 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_GETTER]); | 1404 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_GETTER]); |
1411 } | 1405 } |
1412 | 1406 |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1564 main() { | 1558 main() { |
1565 new PrefixProxy().foo(); | 1559 new PrefixProxy().foo(); |
1566 }'''); | 1560 }'''); |
1567 computeLibrarySourceErrors(source); | 1561 computeLibrarySourceErrors(source); |
1568 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_METHOD]); | 1562 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_METHOD]); |
1569 } | 1563 } |
1570 | 1564 |
1571 void test_undefinedMethod_static_conditionalAccess() { | 1565 void test_undefinedMethod_static_conditionalAccess() { |
1572 // The conditional access operator '?.' cannot be used to access static | 1566 // The conditional access operator '?.' cannot be used to access static |
1573 // methods. | 1567 // methods. |
1574 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); | |
1575 options.enableNullAwareOperators = true; | |
1576 resetWithOptions(options); | |
1577 Source source = addSource(''' | 1568 Source source = addSource(''' |
1578 class A { | 1569 class A { |
1579 static void m() {} | 1570 static void m() {} |
1580 } | 1571 } |
1581 f() { A?.m(); } | 1572 f() { A?.m(); } |
1582 '''); | 1573 '''); |
1583 computeLibrarySourceErrors(source); | 1574 computeLibrarySourceErrors(source); |
1584 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_METHOD]); | 1575 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_METHOD]); |
1585 } | 1576 } |
1586 | 1577 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1656 Source source = addSource(r''' | 1647 Source source = addSource(r''' |
1657 class A {} | 1648 class A {} |
1658 f() { A.B = 0;}'''); | 1649 f() { A.B = 0;}'''); |
1659 computeLibrarySourceErrors(source); | 1650 computeLibrarySourceErrors(source); |
1660 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_SETTER]); | 1651 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_SETTER]); |
1661 } | 1652 } |
1662 | 1653 |
1663 void test_undefinedSetter_static_conditionalAccess() { | 1654 void test_undefinedSetter_static_conditionalAccess() { |
1664 // The conditional access operator '?.' cannot be used to access static | 1655 // The conditional access operator '?.' cannot be used to access static |
1665 // fields. | 1656 // fields. |
1666 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); | |
1667 options.enableNullAwareOperators = true; | |
1668 resetWithOptions(options); | |
1669 Source source = addSource(''' | 1657 Source source = addSource(''' |
1670 class A { | 1658 class A { |
1671 static var x; | 1659 static var x; |
1672 } | 1660 } |
1673 f() { A?.x = 1; } | 1661 f() { A?.x = 1; } |
1674 '''); | 1662 '''); |
1675 computeLibrarySourceErrors(source); | 1663 computeLibrarySourceErrors(source); |
1676 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_SETTER]); | 1664 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_SETTER]); |
1677 } | 1665 } |
1678 | 1666 |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1996 } | 1984 } |
1997 '''); | 1985 '''); |
1998 computeLibrarySourceErrors(source); | 1986 computeLibrarySourceErrors(source); |
1999 assertErrors(source, [ | 1987 assertErrors(source, [ |
2000 StaticTypeWarningCode.YIELD_OF_INVALID_TYPE, | 1988 StaticTypeWarningCode.YIELD_OF_INVALID_TYPE, |
2001 StaticTypeWarningCode.ILLEGAL_SYNC_GENERATOR_RETURN_TYPE | 1989 StaticTypeWarningCode.ILLEGAL_SYNC_GENERATOR_RETURN_TYPE |
2002 ]); | 1990 ]); |
2003 verify([source]); | 1991 verify([source]); |
2004 } | 1992 } |
2005 } | 1993 } |
OLD | NEW |