| OLD | NEW |
| 1 // This code was auto-generated, is not intended to be edited, and is subject to | 1 // This code was auto-generated, is not intended to be edited, and is subject to |
| 2 // significant change. Please see the README file for more information. | 2 // significant change. Please see the README file for more information. |
| 3 library engine.resolver_test; | 3 library engine.resolver_test; |
| 4 import 'dart:collection'; | 4 import 'dart:collection'; |
| 5 import 'package:analyzer_experimental/src/generated/java_core.dart'; | 5 import 'package:analyzer_experimental/src/generated/java_core.dart'; |
| 6 import 'package:analyzer_experimental/src/generated/java_engine.dart'; | 6 import 'package:analyzer_experimental/src/generated/java_engine.dart'; |
| 7 import 'package:analyzer_experimental/src/generated/java_junit.dart'; | 7 import 'package:analyzer_experimental/src/generated/java_junit.dart'; |
| 8 import 'package:analyzer_experimental/src/generated/source_io.dart'; | 8 import 'package:analyzer_experimental/src/generated/source_io.dart'; |
| 9 import 'package:analyzer_experimental/src/generated/error.dart'; | 9 import 'package:analyzer_experimental/src/generated/error.dart'; |
| 10 import 'package:analyzer_experimental/src/generated/scanner.dart'; | 10 import 'package:analyzer_experimental/src/generated/scanner.dart'; |
| (...skipping 1482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1493 } | 1493 } |
| 1494 void test_nonConstMapAsExpressionStatement_typeArguments() { | 1494 void test_nonConstMapAsExpressionStatement_typeArguments() { |
| 1495 Source source = addSource(EngineTestCase.createSource(["f() {", " <String,
int> {'a' : 0, 'b' : 1};", "}"])); | 1495 Source source = addSource(EngineTestCase.createSource(["f() {", " <String,
int> {'a' : 0, 'b' : 1};", "}"])); |
| 1496 resolve(source); | 1496 resolve(source); |
| 1497 assertNoErrors(); | 1497 assertNoErrors(); |
| 1498 verify([source]); | 1498 verify([source]); |
| 1499 } | 1499 } |
| 1500 void test_nonConstValueInInitializer_binary_bool() { | 1500 void test_nonConstValueInInitializer_binary_bool() { |
| 1501 Source source = addSource(EngineTestCase.createSource(["class A {", " final
v;", " const A.a1(bool p) : v = p && true;", " const A.a2(bool p) : v = true
&& p;", " const A.b1(bool p) : v = p || true;", " const A.b2(bool p) : v = tru
e || p;", "}"])); | 1501 Source source = addSource(EngineTestCase.createSource(["class A {", " final
v;", " const A.a1(bool p) : v = p && true;", " const A.a2(bool p) : v = true
&& p;", " const A.b1(bool p) : v = p || true;", " const A.b2(bool p) : v = tru
e || p;", "}"])); |
| 1502 resolve(source); | 1502 resolve(source); |
| 1503 assertErrors([AuditCode.DEAD_CODE]); | 1503 assertErrors([HintCode.DEAD_CODE]); |
| 1504 verify([source]); | 1504 verify([source]); |
| 1505 } | 1505 } |
| 1506 void test_nonConstValueInInitializer_binary_dynamic() { | 1506 void test_nonConstValueInInitializer_binary_dynamic() { |
| 1507 Source source = addSource(EngineTestCase.createSource(["class A {", " final
v;", " const A.a1(p) : v = p + 5;", " const A.a2(p) : v = 5 + p;", " const A
.b1(p) : v = p - 5;", " const A.b2(p) : v = 5 - p;", " const A.c1(p) : v = p *
5;", " const A.c2(p) : v = 5 * p;", " const A.d1(p) : v = p / 5;", " const A
.d2(p) : v = 5 / p;", " const A.e1(p) : v = p ~/ 5;", " const A.e2(p) : v = 5
~/ p;", " const A.f1(p) : v = p > 5;", " const A.f2(p) : v = 5 > p;", " const
A.g1(p) : v = p < 5;", " const A.g2(p) : v = 5 < p;", " const A.h1(p) : v = p
>= 5;", " const A.h2(p) : v = 5 >= p;", " const A.i1(p) : v = p <= 5;", " co
nst A.i2(p) : v = 5 <= p;", " const A.j1(p) : v = p % 5;", " const A.j2(p) : v
= 5 % p;", "}"])); | 1507 Source source = addSource(EngineTestCase.createSource(["class A {", " final
v;", " const A.a1(p) : v = p + 5;", " const A.a2(p) : v = 5 + p;", " const A
.b1(p) : v = p - 5;", " const A.b2(p) : v = 5 - p;", " const A.c1(p) : v = p *
5;", " const A.c2(p) : v = 5 * p;", " const A.d1(p) : v = p / 5;", " const A
.d2(p) : v = 5 / p;", " const A.e1(p) : v = p ~/ 5;", " const A.e2(p) : v = 5
~/ p;", " const A.f1(p) : v = p > 5;", " const A.f2(p) : v = 5 > p;", " const
A.g1(p) : v = p < 5;", " const A.g2(p) : v = 5 < p;", " const A.h1(p) : v = p
>= 5;", " const A.h2(p) : v = 5 >= p;", " const A.i1(p) : v = p <= 5;", " co
nst A.i2(p) : v = 5 <= p;", " const A.j1(p) : v = p % 5;", " const A.j2(p) : v
= 5 % p;", "}"])); |
| 1508 resolve(source); | 1508 resolve(source); |
| 1509 assertNoErrors(); | 1509 assertNoErrors(); |
| 1510 } | 1510 } |
| 1511 void test_nonConstValueInInitializer_binary_int() { | 1511 void test_nonConstValueInInitializer_binary_int() { |
| 1512 Source source = addSource(EngineTestCase.createSource(["class A {", " final
v;", " const A.a1(int p) : v = p ^ 5;", " const A.a2(int p) : v = 5 ^ p;", "
const A.b1(int p) : v = p & 5;", " const A.b2(int p) : v = 5 & p;", " const A
.c1(int p) : v = p | 5;", " const A.c2(int p) : v = 5 | p;", " const A.d1(int
p) : v = p >> 5;", " const A.d2(int p) : v = 5 >> p;", " const A.e1(int p) : v
= p << 5;", " const A.e2(int p) : v = 5 << p;", "}"])); | 1512 Source source = addSource(EngineTestCase.createSource(["class A {", " final
v;", " const A.a1(int p) : v = p ^ 5;", " const A.a2(int p) : v = 5 ^ p;", "
const A.b1(int p) : v = p & 5;", " const A.b2(int p) : v = 5 & p;", " const A
.c1(int p) : v = p | 5;", " const A.c2(int p) : v = 5 | p;", " const A.d1(int
p) : v = p >> 5;", " const A.d2(int p) : v = 5 >> p;", " const A.e1(int p) : v
= p << 5;", " const A.e2(int p) : v = 5 << p;", "}"])); |
| 1513 resolve(source); | 1513 resolve(source); |
| (...skipping 1998 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3512 final __test = new StaticTypeWarningCodeTest(); | 3512 final __test = new StaticTypeWarningCodeTest(); |
| 3513 runJUnitTest(__test, __test.test_wrongNumberOfTypeArguments_typeTest_too
Few); | 3513 runJUnitTest(__test, __test.test_wrongNumberOfTypeArguments_typeTest_too
Few); |
| 3514 }); | 3514 }); |
| 3515 _ut.test('test_wrongNumberOfTypeArguments_typeTest_tooMany', () { | 3515 _ut.test('test_wrongNumberOfTypeArguments_typeTest_tooMany', () { |
| 3516 final __test = new StaticTypeWarningCodeTest(); | 3516 final __test = new StaticTypeWarningCodeTest(); |
| 3517 runJUnitTest(__test, __test.test_wrongNumberOfTypeArguments_typeTest_too
Many); | 3517 runJUnitTest(__test, __test.test_wrongNumberOfTypeArguments_typeTest_too
Many); |
| 3518 }); | 3518 }); |
| 3519 }); | 3519 }); |
| 3520 } | 3520 } |
| 3521 } | 3521 } |
| 3522 class HintCodeTest extends ResolverTestCase { |
| 3523 void test_deadCode_deadBlock_conditionalElse() { |
| 3524 Source source = addSource(EngineTestCase.createSource(["f() {", " true ? 1
: 2;", "}"])); |
| 3525 resolve(source); |
| 3526 assertErrors([HintCode.DEAD_CODE]); |
| 3527 verify([source]); |
| 3528 } |
| 3529 void test_deadCode_deadBlock_conditionalIf() { |
| 3530 Source source = addSource(EngineTestCase.createSource(["f() {", " false ? 1
: 2;", "}"])); |
| 3531 resolve(source); |
| 3532 assertErrors([HintCode.DEAD_CODE]); |
| 3533 verify([source]); |
| 3534 } |
| 3535 void test_deadCode_deadBlock_else() { |
| 3536 Source source = addSource(EngineTestCase.createSource(["f() {", " if(true)
{", " } else {", " }", "}"])); |
| 3537 resolve(source); |
| 3538 assertErrors([HintCode.DEAD_CODE]); |
| 3539 verify([source]); |
| 3540 } |
| 3541 void test_deadCode_deadBlock_if() { |
| 3542 Source source = addSource(EngineTestCase.createSource(["f() {", " if(false)
{}", "}"])); |
| 3543 resolve(source); |
| 3544 assertErrors([HintCode.DEAD_CODE]); |
| 3545 verify([source]); |
| 3546 } |
| 3547 void test_deadCode_deadBlock_if_nested() { |
| 3548 Source source = addSource(EngineTestCase.createSource(["f() {", " if(false)
{if(false) {}}", "}"])); |
| 3549 resolve(source); |
| 3550 assertErrors([HintCode.DEAD_CODE]); |
| 3551 verify([source]); |
| 3552 } |
| 3553 void test_deadCode_deadBlock_while() { |
| 3554 Source source = addSource(EngineTestCase.createSource(["f() {", " while(fal
se) {}", "}"])); |
| 3555 resolve(source); |
| 3556 assertErrors([HintCode.DEAD_CODE]); |
| 3557 verify([source]); |
| 3558 } |
| 3559 void test_deadCode_deadCatch_catchFollowingCatch() { |
| 3560 Source source = addSource(EngineTestCase.createSource(["class A {}", "f() {"
, " try {} catch (e) {} catch (e) {}", "}"])); |
| 3561 resolve(source); |
| 3562 assertErrors([HintCode.DEAD_CODE_CATCH_FOLLOWING_CATCH]); |
| 3563 verify([source]); |
| 3564 } |
| 3565 void test_deadCode_deadCatch_catchFollowingCatch_object() { |
| 3566 Source source = addSource(EngineTestCase.createSource(["f() {", " try {} on
Object catch (e) {} catch (e) {}", "}"])); |
| 3567 resolve(source); |
| 3568 assertErrors([HintCode.DEAD_CODE_CATCH_FOLLOWING_CATCH]); |
| 3569 verify([source]); |
| 3570 } |
| 3571 void test_deadCode_deadCatch_onCatchSubtype() { |
| 3572 Source source = addSource(EngineTestCase.createSource(["class A {}", "class
B extends A {}", "f() {", " try {} on A catch (e) {} on B catch (e) {}", "}"]))
; |
| 3573 resolve(source); |
| 3574 assertErrors([HintCode.DEAD_CODE_ON_CATCH_SUBTYPE]); |
| 3575 verify([source]); |
| 3576 } |
| 3577 void test_deadCode_deadOperandLHS_and() { |
| 3578 Source source = addSource(EngineTestCase.createSource(["f(bool b) {", " boo
l c = false && b;", "}"])); |
| 3579 resolve(source); |
| 3580 assertErrors([HintCode.DEAD_CODE]); |
| 3581 verify([source]); |
| 3582 } |
| 3583 void test_deadCode_deadOperandLHS_or() { |
| 3584 Source source = addSource(EngineTestCase.createSource(["f(bool b) {", " boo
l c = true || b;", "}"])); |
| 3585 resolve(source); |
| 3586 assertErrors([HintCode.DEAD_CODE]); |
| 3587 verify([source]); |
| 3588 } |
| 3589 void test_deadCode_statementAfterReturn_function() { |
| 3590 Source source = addSource(EngineTestCase.createSource(["f() {", " var one =
1;", " return;", " var two = 2;", "}"])); |
| 3591 resolve(source); |
| 3592 assertErrors([HintCode.DEAD_CODE]); |
| 3593 verify([source]); |
| 3594 } |
| 3595 void test_deadCode_statementAfterReturn_ifStatement() { |
| 3596 Source source = addSource(EngineTestCase.createSource(["f(bool b) {", " if(
b) {", " var one = 1;", " return;", " var two = 2;", " }", "}"])); |
| 3597 resolve(source); |
| 3598 assertErrors([HintCode.DEAD_CODE]); |
| 3599 verify([source]); |
| 3600 } |
| 3601 void test_deadCode_statementAfterReturn_method() { |
| 3602 Source source = addSource(EngineTestCase.createSource(["class A {", " m() {
", " var one = 1;", " return;", " var two = 2;", " }", "}"])); |
| 3603 resolve(source); |
| 3604 assertErrors([HintCode.DEAD_CODE]); |
| 3605 verify([source]); |
| 3606 } |
| 3607 void test_deadCode_statementAfterReturn_twoReturns() { |
| 3608 Source source = addSource(EngineTestCase.createSource(["f() {", " var one =
1;", " return;", " var two = 2;", " return;", " var three = 3;", "}"])); |
| 3609 resolve(source); |
| 3610 assertErrors([HintCode.DEAD_CODE]); |
| 3611 verify([source]); |
| 3612 } |
| 3613 static dartSuite() { |
| 3614 _ut.group('HintCodeTest', () { |
| 3615 _ut.test('test_deadCode_deadBlock_conditionalElse', () { |
| 3616 final __test = new HintCodeTest(); |
| 3617 runJUnitTest(__test, __test.test_deadCode_deadBlock_conditionalElse); |
| 3618 }); |
| 3619 _ut.test('test_deadCode_deadBlock_conditionalIf', () { |
| 3620 final __test = new HintCodeTest(); |
| 3621 runJUnitTest(__test, __test.test_deadCode_deadBlock_conditionalIf); |
| 3622 }); |
| 3623 _ut.test('test_deadCode_deadBlock_else', () { |
| 3624 final __test = new HintCodeTest(); |
| 3625 runJUnitTest(__test, __test.test_deadCode_deadBlock_else); |
| 3626 }); |
| 3627 _ut.test('test_deadCode_deadBlock_if', () { |
| 3628 final __test = new HintCodeTest(); |
| 3629 runJUnitTest(__test, __test.test_deadCode_deadBlock_if); |
| 3630 }); |
| 3631 _ut.test('test_deadCode_deadBlock_if_nested', () { |
| 3632 final __test = new HintCodeTest(); |
| 3633 runJUnitTest(__test, __test.test_deadCode_deadBlock_if_nested); |
| 3634 }); |
| 3635 _ut.test('test_deadCode_deadBlock_while', () { |
| 3636 final __test = new HintCodeTest(); |
| 3637 runJUnitTest(__test, __test.test_deadCode_deadBlock_while); |
| 3638 }); |
| 3639 _ut.test('test_deadCode_deadCatch_catchFollowingCatch', () { |
| 3640 final __test = new HintCodeTest(); |
| 3641 runJUnitTest(__test, __test.test_deadCode_deadCatch_catchFollowingCatch)
; |
| 3642 }); |
| 3643 _ut.test('test_deadCode_deadCatch_catchFollowingCatch_object', () { |
| 3644 final __test = new HintCodeTest(); |
| 3645 runJUnitTest(__test, __test.test_deadCode_deadCatch_catchFollowingCatch_
object); |
| 3646 }); |
| 3647 _ut.test('test_deadCode_deadCatch_onCatchSubtype', () { |
| 3648 final __test = new HintCodeTest(); |
| 3649 runJUnitTest(__test, __test.test_deadCode_deadCatch_onCatchSubtype); |
| 3650 }); |
| 3651 _ut.test('test_deadCode_deadOperandLHS_and', () { |
| 3652 final __test = new HintCodeTest(); |
| 3653 runJUnitTest(__test, __test.test_deadCode_deadOperandLHS_and); |
| 3654 }); |
| 3655 _ut.test('test_deadCode_deadOperandLHS_or', () { |
| 3656 final __test = new HintCodeTest(); |
| 3657 runJUnitTest(__test, __test.test_deadCode_deadOperandLHS_or); |
| 3658 }); |
| 3659 _ut.test('test_deadCode_statementAfterReturn_function', () { |
| 3660 final __test = new HintCodeTest(); |
| 3661 runJUnitTest(__test, __test.test_deadCode_statementAfterReturn_function)
; |
| 3662 }); |
| 3663 _ut.test('test_deadCode_statementAfterReturn_ifStatement', () { |
| 3664 final __test = new HintCodeTest(); |
| 3665 runJUnitTest(__test, __test.test_deadCode_statementAfterReturn_ifStateme
nt); |
| 3666 }); |
| 3667 _ut.test('test_deadCode_statementAfterReturn_method', () { |
| 3668 final __test = new HintCodeTest(); |
| 3669 runJUnitTest(__test, __test.test_deadCode_statementAfterReturn_method); |
| 3670 }); |
| 3671 _ut.test('test_deadCode_statementAfterReturn_twoReturns', () { |
| 3672 final __test = new HintCodeTest(); |
| 3673 runJUnitTest(__test, __test.test_deadCode_statementAfterReturn_twoReturn
s); |
| 3674 }); |
| 3675 }); |
| 3676 } |
| 3677 } |
| 3522 class TypeResolverVisitorTest extends EngineTestCase { | 3678 class TypeResolverVisitorTest extends EngineTestCase { |
| 3523 | 3679 |
| 3524 /** | 3680 /** |
| 3525 * The error listener to which errors will be reported. | 3681 * The error listener to which errors will be reported. |
| 3526 */ | 3682 */ |
| 3527 GatheringErrorListener _listener; | 3683 GatheringErrorListener _listener; |
| 3528 | 3684 |
| 3529 /** | 3685 /** |
| 3530 * The object representing the information about the library in which the type
s are being | 3686 * The object representing the information about the library in which the type
s are being |
| 3531 * resolved. | 3687 * resolved. |
| (...skipping 1321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4853 assertErrors([CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION]); | 5009 assertErrors([CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION]); |
| 4854 verify([source]); | 5010 verify([source]); |
| 4855 } | 5011 } |
| 4856 void test_constEvalTypeBool_binary() { | 5012 void test_constEvalTypeBool_binary() { |
| 4857 check_constEvalTypeBool_withParameter_binary("p && ''"); | 5013 check_constEvalTypeBool_withParameter_binary("p && ''"); |
| 4858 check_constEvalTypeBool_withParameter_binary("p || ''"); | 5014 check_constEvalTypeBool_withParameter_binary("p || ''"); |
| 4859 } | 5015 } |
| 4860 void test_constEvalTypeBool_binary_leftTrue() { | 5016 void test_constEvalTypeBool_binary_leftTrue() { |
| 4861 Source source = addSource("const C = (true || 0);"); | 5017 Source source = addSource("const C = (true || 0);"); |
| 4862 resolve(source); | 5018 resolve(source); |
| 4863 assertErrors([CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL, AuditCode.DEAD_CODE
]); | 5019 assertErrors([CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL, HintCode.DEAD_CODE]
); |
| 4864 verify([source]); | 5020 verify([source]); |
| 4865 } | 5021 } |
| 4866 void test_constEvalTypeBoolNumString_equal() { | 5022 void test_constEvalTypeBoolNumString_equal() { |
| 4867 Source source = addSource(EngineTestCase.createSource(["class A {", " const
A();", "}", "class B {", " final a;", " const B(num p) : a = p == const A();"
, "}"])); | 5023 Source source = addSource(EngineTestCase.createSource(["class A {", " const
A();", "}", "class B {", " final a;", " const B(num p) : a = p == const A();"
, "}"])); |
| 4868 resolve(source); | 5024 resolve(source); |
| 4869 assertErrors([CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL_NUM_STRING]); | 5025 assertErrors([CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL_NUM_STRING]); |
| 4870 verify([source]); | 5026 verify([source]); |
| 4871 } | 5027 } |
| 4872 void test_constEvalTypeBoolNumString_notEqual() { | 5028 void test_constEvalTypeBoolNumString_notEqual() { |
| 4873 Source source = addSource(EngineTestCase.createSource(["class A {", " const
A();", "}", "class B {", " final a;", " const B(String p) : a = p != const A(
);", "}"])); | 5029 Source source = addSource(EngineTestCase.createSource(["class A {", " const
A();", "}", "class B {", " final a;", " const B(String p) : a = p != const A(
);", "}"])); |
| (...skipping 2792 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7666 } else { | 7822 } else { |
| 7667 return "<unknown file- CompilationUnit.getElement() returned null>"; | 7823 return "<unknown file- CompilationUnit.getElement() returned null>"; |
| 7668 } | 7824 } |
| 7669 } else { | 7825 } else { |
| 7670 return "<unknown file- CompilationUnit.getRoot() is not a CompilationUni
t>"; | 7826 return "<unknown file- CompilationUnit.getRoot() is not a CompilationUni
t>"; |
| 7671 } | 7827 } |
| 7672 } | 7828 } |
| 7673 return "<unknown file- ASTNode is null>"; | 7829 return "<unknown file- ASTNode is null>"; |
| 7674 } | 7830 } |
| 7675 } | 7831 } |
| 7676 class AuditCodeTest extends ResolverTestCase { | |
| 7677 void test_deadCode_deadBlock_conditionalElse() { | |
| 7678 Source source = addSource(EngineTestCase.createSource(["f() {", " true ? 1
: 2;", "}"])); | |
| 7679 resolve(source); | |
| 7680 assertErrors([AuditCode.DEAD_CODE]); | |
| 7681 verify([source]); | |
| 7682 } | |
| 7683 void test_deadCode_deadBlock_conditionalIf() { | |
| 7684 Source source = addSource(EngineTestCase.createSource(["f() {", " false ? 1
: 2;", "}"])); | |
| 7685 resolve(source); | |
| 7686 assertErrors([AuditCode.DEAD_CODE]); | |
| 7687 verify([source]); | |
| 7688 } | |
| 7689 void test_deadCode_deadBlock_else() { | |
| 7690 Source source = addSource(EngineTestCase.createSource(["f() {", " if(true)
{", " } else {", " }", "}"])); | |
| 7691 resolve(source); | |
| 7692 assertErrors([AuditCode.DEAD_CODE]); | |
| 7693 verify([source]); | |
| 7694 } | |
| 7695 void test_deadCode_deadBlock_if() { | |
| 7696 Source source = addSource(EngineTestCase.createSource(["f() {", " if(false)
{}", "}"])); | |
| 7697 resolve(source); | |
| 7698 assertErrors([AuditCode.DEAD_CODE]); | |
| 7699 verify([source]); | |
| 7700 } | |
| 7701 void test_deadCode_deadBlock_while() { | |
| 7702 Source source = addSource(EngineTestCase.createSource(["f() {", " while(fal
se) {}", "}"])); | |
| 7703 resolve(source); | |
| 7704 assertErrors([AuditCode.DEAD_CODE]); | |
| 7705 verify([source]); | |
| 7706 } | |
| 7707 void test_deadCode_deadOperandLHS_and() { | |
| 7708 Source source = addSource(EngineTestCase.createSource(["f(bool b) {", " boo
l c = false && b;", "}"])); | |
| 7709 resolve(source); | |
| 7710 assertErrors([AuditCode.DEAD_CODE]); | |
| 7711 verify([source]); | |
| 7712 } | |
| 7713 void test_deadCode_deadOperandLHS_or() { | |
| 7714 Source source = addSource(EngineTestCase.createSource(["f(bool b) {", " boo
l c = true || b;", "}"])); | |
| 7715 resolve(source); | |
| 7716 assertErrors([AuditCode.DEAD_CODE]); | |
| 7717 verify([source]); | |
| 7718 } | |
| 7719 void test_deadCode_statementAfterReturn_function() { | |
| 7720 Source source = addSource(EngineTestCase.createSource(["f() {", " var one =
1;", " return;", " var two = 2;", "}"])); | |
| 7721 resolve(source); | |
| 7722 assertErrors([AuditCode.DEAD_CODE]); | |
| 7723 verify([source]); | |
| 7724 } | |
| 7725 void test_deadCode_statementAfterReturn_ifStatement() { | |
| 7726 Source source = addSource(EngineTestCase.createSource(["f(bool b) {", " if(
b) {", " var one = 1;", " return;", " var two = 2;", " }", "}"])); | |
| 7727 resolve(source); | |
| 7728 assertErrors([AuditCode.DEAD_CODE]); | |
| 7729 verify([source]); | |
| 7730 } | |
| 7731 void test_deadCode_statementAfterReturn_method() { | |
| 7732 Source source = addSource(EngineTestCase.createSource(["class A {", " m() {
", " var one = 1;", " return;", " var two = 2;", " }", "}"])); | |
| 7733 resolve(source); | |
| 7734 assertErrors([AuditCode.DEAD_CODE]); | |
| 7735 verify([source]); | |
| 7736 } | |
| 7737 void test_deadCode_statementAfterReturn_twoReturns() { | |
| 7738 Source source = addSource(EngineTestCase.createSource(["f() {", " var one =
1;", " return;", " var two = 2;", " return;", " var three = 3;", "}"])); | |
| 7739 resolve(source); | |
| 7740 assertErrors([AuditCode.DEAD_CODE]); | |
| 7741 verify([source]); | |
| 7742 } | |
| 7743 static dartSuite() { | |
| 7744 _ut.group('AuditCodeTest', () { | |
| 7745 _ut.test('test_deadCode_deadBlock_conditionalElse', () { | |
| 7746 final __test = new AuditCodeTest(); | |
| 7747 runJUnitTest(__test, __test.test_deadCode_deadBlock_conditionalElse); | |
| 7748 }); | |
| 7749 _ut.test('test_deadCode_deadBlock_conditionalIf', () { | |
| 7750 final __test = new AuditCodeTest(); | |
| 7751 runJUnitTest(__test, __test.test_deadCode_deadBlock_conditionalIf); | |
| 7752 }); | |
| 7753 _ut.test('test_deadCode_deadBlock_else', () { | |
| 7754 final __test = new AuditCodeTest(); | |
| 7755 runJUnitTest(__test, __test.test_deadCode_deadBlock_else); | |
| 7756 }); | |
| 7757 _ut.test('test_deadCode_deadBlock_if', () { | |
| 7758 final __test = new AuditCodeTest(); | |
| 7759 runJUnitTest(__test, __test.test_deadCode_deadBlock_if); | |
| 7760 }); | |
| 7761 _ut.test('test_deadCode_deadBlock_while', () { | |
| 7762 final __test = new AuditCodeTest(); | |
| 7763 runJUnitTest(__test, __test.test_deadCode_deadBlock_while); | |
| 7764 }); | |
| 7765 _ut.test('test_deadCode_deadOperandLHS_and', () { | |
| 7766 final __test = new AuditCodeTest(); | |
| 7767 runJUnitTest(__test, __test.test_deadCode_deadOperandLHS_and); | |
| 7768 }); | |
| 7769 _ut.test('test_deadCode_deadOperandLHS_or', () { | |
| 7770 final __test = new AuditCodeTest(); | |
| 7771 runJUnitTest(__test, __test.test_deadCode_deadOperandLHS_or); | |
| 7772 }); | |
| 7773 _ut.test('test_deadCode_statementAfterReturn_function', () { | |
| 7774 final __test = new AuditCodeTest(); | |
| 7775 runJUnitTest(__test, __test.test_deadCode_statementAfterReturn_function)
; | |
| 7776 }); | |
| 7777 _ut.test('test_deadCode_statementAfterReturn_ifStatement', () { | |
| 7778 final __test = new AuditCodeTest(); | |
| 7779 runJUnitTest(__test, __test.test_deadCode_statementAfterReturn_ifStateme
nt); | |
| 7780 }); | |
| 7781 _ut.test('test_deadCode_statementAfterReturn_method', () { | |
| 7782 final __test = new AuditCodeTest(); | |
| 7783 runJUnitTest(__test, __test.test_deadCode_statementAfterReturn_method); | |
| 7784 }); | |
| 7785 _ut.test('test_deadCode_statementAfterReturn_twoReturns', () { | |
| 7786 final __test = new AuditCodeTest(); | |
| 7787 runJUnitTest(__test, __test.test_deadCode_statementAfterReturn_twoReturn
s); | |
| 7788 }); | |
| 7789 }); | |
| 7790 } | |
| 7791 } | |
| 7792 /** | 7832 /** |
| 7793 * The class `StrictModeTest` contains tests to ensure that the correct errors a
nd warnings | 7833 * The class `StrictModeTest` contains tests to ensure that the correct errors a
nd warnings |
| 7794 * are reported when the analysis engine is run in strict mode. | 7834 * are reported when the analysis engine is run in strict mode. |
| 7795 */ | 7835 */ |
| 7796 class StrictModeTest extends ResolverTestCase { | 7836 class StrictModeTest extends ResolverTestCase { |
| 7797 void fail_for() { | 7837 void fail_for() { |
| 7798 Source source = addSource(EngineTestCase.createSource(["int f(List<int> list
) {", " num sum = 0;", " for (num i = 0; i < list.length; i++) {", " sum +=
list[i];", " }", "}"])); | 7838 Source source = addSource(EngineTestCase.createSource(["int f(List<int> list
) {", " num sum = 0;", " for (num i = 0; i < list.length; i++) {", " sum +=
list[i];", " }", "}"])); |
| 7799 resolve(source); | 7839 resolve(source); |
| 7800 assertErrors([StaticTypeWarningCode.UNDEFINED_OPERATOR]); | 7840 assertErrors([StaticTypeWarningCode.UNDEFINED_OPERATOR]); |
| 7801 } | 7841 } |
| (...skipping 2882 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10684 | 10724 |
| 10685 /** | 10725 /** |
| 10686 * A list containing all of the AST nodes that were resolved to an element of
the wrong type. | 10726 * A list containing all of the AST nodes that were resolved to an element of
the wrong type. |
| 10687 */ | 10727 */ |
| 10688 List<ASTNode> _wrongTypedNodes = new List<ASTNode>(); | 10728 List<ASTNode> _wrongTypedNodes = new List<ASTNode>(); |
| 10689 | 10729 |
| 10690 /** | 10730 /** |
| 10691 * Initialize a newly created verifier to verify that all of the nodes in the
visited AST | 10731 * Initialize a newly created verifier to verify that all of the nodes in the
visited AST |
| 10692 * structures that are expected to have been resolved have an element associat
ed with them. | 10732 * structures that are expected to have been resolved have an element associat
ed with them. |
| 10693 */ | 10733 */ |
| 10694 ResolutionVerifier() { | 10734 ResolutionVerifier() : this.con1(null); |
| 10695 _jtd_constructor_366_impl(); | |
| 10696 } | |
| 10697 _jtd_constructor_366_impl() { | |
| 10698 _jtd_constructor_367_impl(null); | |
| 10699 } | |
| 10700 | 10735 |
| 10701 /** | 10736 /** |
| 10702 * Initialize a newly created verifier to verify that all of the identifiers i
n the visited AST | 10737 * Initialize a newly created verifier to verify that all of the identifiers i
n the visited AST |
| 10703 * structures that are expected to have been resolved have an element associat
ed with them. Nodes | 10738 * structures that are expected to have been resolved have an element associat
ed with them. Nodes |
| 10704 * in the set of known exceptions are not expected to have been resolved, even
if they normally | 10739 * in the set of known exceptions are not expected to have been resolved, even
if they normally |
| 10705 * would have been expected to have been resolved. | 10740 * would have been expected to have been resolved. |
| 10706 * | 10741 * |
| 10707 * @param knownExceptions a set containing nodes that are known to not be reso
lvable and should | 10742 * @param knownExceptions a set containing nodes that are known to not be reso
lvable and should |
| 10708 * therefore not cause the test to fail | 10743 * therefore not cause the test to fail |
| 10709 **/ | 10744 **/ |
| 10710 ResolutionVerifier.con1(Set<ASTNode> knownExceptions2) { | 10745 ResolutionVerifier.con1(Set<ASTNode> knownExceptions) { |
| 10711 _jtd_constructor_367_impl(knownExceptions2); | 10746 this._knownExceptions = knownExceptions; |
| 10712 } | |
| 10713 _jtd_constructor_367_impl(Set<ASTNode> knownExceptions2) { | |
| 10714 this._knownExceptions = knownExceptions2; | |
| 10715 } | 10747 } |
| 10716 | 10748 |
| 10717 /** | 10749 /** |
| 10718 * Assert that all of the visited identifiers were resolved. | 10750 * Assert that all of the visited identifiers were resolved. |
| 10719 */ | 10751 */ |
| 10720 void assertResolved() { | 10752 void assertResolved() { |
| 10721 if (!_unresolvedNodes.isEmpty || !_wrongTypedNodes.isEmpty) { | 10753 if (!_unresolvedNodes.isEmpty || !_wrongTypedNodes.isEmpty) { |
| 10722 PrintStringWriter writer = new PrintStringWriter(); | 10754 PrintStringWriter writer = new PrintStringWriter(); |
| 10723 if (!_unresolvedNodes.isEmpty) { | 10755 if (!_unresolvedNodes.isEmpty) { |
| 10724 writer.print("Failed to resolve "); | 10756 writer.print("Failed to resolve "); |
| (...skipping 1213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11938 final __test = new StaticTypeAnalyzerTest(); | 11970 final __test = new StaticTypeAnalyzerTest(); |
| 11939 runJUnitTest(__test, __test.test_visitThrowExpression_withValue); | 11971 runJUnitTest(__test, __test.test_visitThrowExpression_withValue); |
| 11940 }); | 11972 }); |
| 11941 _ut.test('test_visitThrowExpression_withoutValue', () { | 11973 _ut.test('test_visitThrowExpression_withoutValue', () { |
| 11942 final __test = new StaticTypeAnalyzerTest(); | 11974 final __test = new StaticTypeAnalyzerTest(); |
| 11943 runJUnitTest(__test, __test.test_visitThrowExpression_withoutValue); | 11975 runJUnitTest(__test, __test.test_visitThrowExpression_withoutValue); |
| 11944 }); | 11976 }); |
| 11945 }); | 11977 }); |
| 11946 } | 11978 } |
| 11947 } | 11979 } |
| 11980 class NonHintCodeTest extends ResolverTestCase { |
| 11981 void test_deadCode_deadCatch_onCatchSubtype() { |
| 11982 Source source = addSource(EngineTestCase.createSource(["class A {}", "class
B extends A {}", "f() {", " try {} on B catch (e) {} on A catch (e) {} catch (e
) {}", "}"])); |
| 11983 resolve(source); |
| 11984 assertNoErrors(); |
| 11985 verify([source]); |
| 11986 } |
| 11987 static dartSuite() { |
| 11988 _ut.group('NonHintCodeTest', () { |
| 11989 _ut.test('test_deadCode_deadCatch_onCatchSubtype', () { |
| 11990 final __test = new NonHintCodeTest(); |
| 11991 runJUnitTest(__test, __test.test_deadCode_deadCatch_onCatchSubtype); |
| 11992 }); |
| 11993 }); |
| 11994 } |
| 11995 } |
| 11948 class EnclosedScopeTest extends ResolverTestCase { | 11996 class EnclosedScopeTest extends ResolverTestCase { |
| 11949 void test_define_duplicate() { | 11997 void test_define_duplicate() { |
| 11950 LibraryElement definingLibrary2 = createTestLibrary(); | 11998 LibraryElement definingLibrary2 = createTestLibrary(); |
| 11951 GatheringErrorListener errorListener2 = new GatheringErrorListener(); | 11999 GatheringErrorListener errorListener2 = new GatheringErrorListener(); |
| 11952 Scope rootScope = new Scope_17(definingLibrary2, errorListener2); | 12000 Scope rootScope = new Scope_17(definingLibrary2, errorListener2); |
| 11953 EnclosedScope scope = new EnclosedScope(rootScope); | 12001 EnclosedScope scope = new EnclosedScope(rootScope); |
| 11954 VariableElement element1 = ElementFactory.localVariableElement(ASTFactory.id
entifier3("v1")); | 12002 VariableElement element1 = ElementFactory.localVariableElement(ASTFactory.id
entifier3("v1")); |
| 11955 VariableElement element2 = ElementFactory.localVariableElement(ASTFactory.id
entifier3("v1")); | 12003 VariableElement element2 = ElementFactory.localVariableElement(ASTFactory.id
entifier3("v1")); |
| 11956 scope.define(element1); | 12004 scope.define(element1); |
| 11957 scope.define(element2); | 12005 scope.define(element2); |
| (...skipping 855 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12813 // LibraryElementBuilderTest.dartSuite(); | 12861 // LibraryElementBuilderTest.dartSuite(); |
| 12814 // LibraryTest.dartSuite(); | 12862 // LibraryTest.dartSuite(); |
| 12815 // StaticTypeAnalyzerTest.dartSuite(); | 12863 // StaticTypeAnalyzerTest.dartSuite(); |
| 12816 // TypeOverrideManagerTest.dartSuite(); | 12864 // TypeOverrideManagerTest.dartSuite(); |
| 12817 // TypeProviderImplTest.dartSuite(); | 12865 // TypeProviderImplTest.dartSuite(); |
| 12818 // TypeResolverVisitorTest.dartSuite(); | 12866 // TypeResolverVisitorTest.dartSuite(); |
| 12819 // EnclosedScopeTest.dartSuite(); | 12867 // EnclosedScopeTest.dartSuite(); |
| 12820 // LibraryImportScopeTest.dartSuite(); | 12868 // LibraryImportScopeTest.dartSuite(); |
| 12821 // LibraryScopeTest.dartSuite(); | 12869 // LibraryScopeTest.dartSuite(); |
| 12822 // ScopeTest.dartSuite(); | 12870 // ScopeTest.dartSuite(); |
| 12823 // AuditCodeTest.dartSuite(); | |
| 12824 // CompileTimeErrorCodeTest.dartSuite(); | 12871 // CompileTimeErrorCodeTest.dartSuite(); |
| 12825 // ErrorResolverTest.dartSuite(); | 12872 // ErrorResolverTest.dartSuite(); |
| 12873 // HintCodeTest.dartSuite(); |
| 12874 // NonHintCodeTest.dartSuite(); |
| 12826 // NonErrorResolverTest.dartSuite(); | 12875 // NonErrorResolverTest.dartSuite(); |
| 12827 // SimpleResolverTest.dartSuite(); | 12876 // SimpleResolverTest.dartSuite(); |
| 12828 // StaticTypeWarningCodeTest.dartSuite(); | 12877 // StaticTypeWarningCodeTest.dartSuite(); |
| 12829 // StaticWarningCodeTest.dartSuite(); | 12878 // StaticWarningCodeTest.dartSuite(); |
| 12830 // StrictModeTest.dartSuite(); | 12879 // StrictModeTest.dartSuite(); |
| 12831 // TypePropagationTest.dartSuite(); | 12880 // TypePropagationTest.dartSuite(); |
| 12832 } | 12881 } |
| OLD | NEW |