| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 import 'dart:async'; | 5 import 'dart:async'; |
| 6 | 6 |
| 7 import 'package:async_helper/async_helper.dart'; | 7 import 'package:async_helper/async_helper.dart'; |
| 8 import 'package:expect/expect.dart'; | 8 import 'package:expect/expect.dart'; |
| 9 | 9 |
| 10 import 'package:compiler/src/dart_types.dart'; | 10 import 'package:compiler/src/dart_types.dart'; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 import 'package:compiler/src/parser/element_listener.dart'; | 22 import 'package:compiler/src/parser/element_listener.dart'; |
| 23 import 'package:compiler/src/tree/tree.dart'; | 23 import 'package:compiler/src/tree/tree.dart'; |
| 24 import 'package:compiler/src/typechecker.dart'; | 24 import 'package:compiler/src/typechecker.dart'; |
| 25 import 'package:compiler/src/script.dart'; | 25 import 'package:compiler/src/script.dart'; |
| 26 import 'package:compiler/src/util/util.dart'; | 26 import 'package:compiler/src/util/util.dart'; |
| 27 | 27 |
| 28 import 'mock_compiler.dart'; | 28 import 'mock_compiler.dart'; |
| 29 import 'parser_helper.dart'; | 29 import 'parser_helper.dart'; |
| 30 | 30 |
| 31 final MessageKind NOT_ASSIGNABLE = MessageKind.NOT_ASSIGNABLE; | 31 final MessageKind NOT_ASSIGNABLE = MessageKind.NOT_ASSIGNABLE; |
| 32 final MessageKind MEMBER_NOT_FOUND = MessageKind.MEMBER_NOT_FOUND; | 32 final MessageKind UNDEFINED_GETTER = MessageKind.UNDEFINED_GETTER; |
| 33 | 33 |
| 34 main() { | 34 main() { |
| 35 List tests = [testSimpleTypes, | 35 List tests = [testSimpleTypes, |
| 36 testReturn, | 36 testReturn, |
| 37 testFor, | 37 testFor, |
| 38 testSyncForIn, | 38 testSyncForIn, |
| 39 testAsyncForIn, | 39 testAsyncForIn, |
| 40 testWhile, | 40 testWhile, |
| 41 testTry, | 41 testTry, |
| 42 testSwitch, | 42 testSwitch, |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 check("for (;null;) {}"); | 119 check("for (;null;) {}"); |
| 120 check("for (;0;) {}", warnings: NOT_ASSIGNABLE); | 120 check("for (;0;) {}", warnings: NOT_ASSIGNABLE); |
| 121 check("for (;'';) {}", warnings: NOT_ASSIGNABLE); | 121 check("for (;'';) {}", warnings: NOT_ASSIGNABLE); |
| 122 | 122 |
| 123 // Foreach tests | 123 // Foreach tests |
| 124 // TODO(karlklose): for each is not yet implemented. | 124 // TODO(karlklose): for each is not yet implemented. |
| 125 // check("{ List<String> strings = ['1','2','3']; " + | 125 // check("{ List<String> strings = ['1','2','3']; " + |
| 126 // "for (String s in strings) {} }"); | 126 // "for (String s in strings) {} }"); |
| 127 // check("{ List<int> ints = [1,2,3]; for (String s in ints) {} }", | 127 // check("{ List<int> ints = [1,2,3]; for (String s in ints) {} }", |
| 128 // NOT_ASSIGNABLE); | 128 // NOT_ASSIGNABLE); |
| 129 // check("for (String s in true) {}", MessageKind.METHOD_NOT_FOUND); | 129 // check("for (String s in true) {}", MessageKind.UNDEFINED_METHOD); |
| 130 } | 130 } |
| 131 | 131 |
| 132 | 132 |
| 133 testSyncForIn(MockCompiler compiler) { | 133 testSyncForIn(MockCompiler compiler) { |
| 134 String script = """ | 134 String script = """ |
| 135 class HasUntypedIterator { | 135 class HasUntypedIterator { |
| 136 get iterator => null; | 136 get iterator => null; |
| 137 } | 137 } |
| 138 | 138 |
| 139 class HasIntIterator { | 139 class HasIntIterator { |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 }"""); | 207 }"""); |
| 208 analyzeIn(compiler, method, """{ | 208 analyzeIn(compiler, method, """{ |
| 209 for (String e in new HasIntIterator()) {} | 209 for (String e in new HasIntIterator()) {} |
| 210 }""", hints: MessageKind.FORIN_NOT_ASSIGNABLE); | 210 }""", hints: MessageKind.FORIN_NOT_ASSIGNABLE); |
| 211 analyzeIn(compiler, method, """{ | 211 analyzeIn(compiler, method, """{ |
| 212 for (int e in new HasIntIterator()) {} | 212 for (int e in new HasIntIterator()) {} |
| 213 }"""); | 213 }"""); |
| 214 | 214 |
| 215 analyzeIn(compiler, method, """{ | 215 analyzeIn(compiler, method, """{ |
| 216 for (var e in new HasNoIterator()) {} | 216 for (var e in new HasNoIterator()) {} |
| 217 }""", warnings: MessageKind.MEMBER_NOT_FOUND); | 217 }""", warnings: MessageKind.UNDEFINED_GETTER); |
| 218 analyzeIn(compiler, method, """{ | 218 analyzeIn(compiler, method, """{ |
| 219 for (String e in new HasNoIterator()) {} | 219 for (String e in new HasNoIterator()) {} |
| 220 }""", warnings: MessageKind.MEMBER_NOT_FOUND); | 220 }""", warnings: MessageKind.UNDEFINED_GETTER); |
| 221 analyzeIn(compiler, method, """{ | 221 analyzeIn(compiler, method, """{ |
| 222 for (int e in new HasNoIterator()) {} | 222 for (int e in new HasNoIterator()) {} |
| 223 }""", warnings: MessageKind.MEMBER_NOT_FOUND); | 223 }""", warnings: MessageKind.UNDEFINED_GETTER); |
| 224 | 224 |
| 225 analyzeIn(compiler, method, """{ | 225 analyzeIn(compiler, method, """{ |
| 226 for (var e in new HasCustomIntIterator()) {} | 226 for (var e in new HasCustomIntIterator()) {} |
| 227 }"""); | 227 }"""); |
| 228 analyzeIn(compiler, method, """{ | 228 analyzeIn(compiler, method, """{ |
| 229 for (String e in new HasCustomIntIterator()) {} | 229 for (String e in new HasCustomIntIterator()) {} |
| 230 }""", hints: MessageKind.FORIN_NOT_ASSIGNABLE); | 230 }""", hints: MessageKind.FORIN_NOT_ASSIGNABLE); |
| 231 analyzeIn(compiler, method, """{ | 231 analyzeIn(compiler, method, """{ |
| 232 for (int e in new HasCustomIntIterator()) {} | 232 for (int e in new HasCustomIntIterator()) {} |
| 233 }"""); | 233 }"""); |
| 234 | 234 |
| 235 analyzeIn(compiler, method, """{ | 235 analyzeIn(compiler, method, """{ |
| 236 for (var e in new HasCustomNoCurrentIterator()) {} | 236 for (var e in new HasCustomNoCurrentIterator()) {} |
| 237 }""", hints: MessageKind.MEMBER_NOT_FOUND); | 237 }""", hints: MessageKind.UNDEFINED_GETTER); |
| 238 analyzeIn(compiler, method, """{ | 238 analyzeIn(compiler, method, """{ |
| 239 for (String e in new HasCustomNoCurrentIterator()) {} | 239 for (String e in new HasCustomNoCurrentIterator()) {} |
| 240 }""", hints: MessageKind.MEMBER_NOT_FOUND); | 240 }""", hints: MessageKind.UNDEFINED_GETTER); |
| 241 analyzeIn(compiler, method, """{ | 241 analyzeIn(compiler, method, """{ |
| 242 for (int e in new HasCustomNoCurrentIterator()) {} | 242 for (int e in new HasCustomNoCurrentIterator()) {} |
| 243 }""", hints: MessageKind.MEMBER_NOT_FOUND); | 243 }""", hints: MessageKind.UNDEFINED_GETTER); |
| 244 | 244 |
| 245 analyzeIn(compiler, method, """{ | 245 analyzeIn(compiler, method, """{ |
| 246 var localDyn; | 246 var localDyn; |
| 247 for (localDyn in <String>[]) {} | 247 for (localDyn in <String>[]) {} |
| 248 }"""); | 248 }"""); |
| 249 analyzeIn(compiler, method, """{ | 249 analyzeIn(compiler, method, """{ |
| 250 String localString; | 250 String localString; |
| 251 for (localString in <String>[]) {} | 251 for (localString in <String>[]) {} |
| 252 }"""); | 252 }"""); |
| 253 analyzeIn(compiler, method, """{ | 253 analyzeIn(compiler, method, """{ |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 566 check(String code, {warnings}) { | 566 check(String code, {warnings}) { |
| 567 analyze(compiler, code, warnings: warnings); | 567 analyze(compiler, code, warnings: warnings); |
| 568 } | 568 } |
| 569 | 569 |
| 570 // TODO(karlklose): add the DartC tests for operators when we can parse | 570 // TODO(karlklose): add the DartC tests for operators when we can parse |
| 571 // classes with operators. | 571 // classes with operators. |
| 572 for (final op in ['+', '-', '*', '/', '%', '~/', '|', '&']) { | 572 for (final op in ['+', '-', '*', '/', '%', '~/', '|', '&']) { |
| 573 check("{ var i = 1 ${op} 2; }"); | 573 check("{ var i = 1 ${op} 2; }"); |
| 574 check("{ var i = 1; i ${op}= 2; }"); | 574 check("{ var i = 1; i ${op}= 2; }"); |
| 575 check("{ int i; var j = (i = true) ${op} 2; }", | 575 check("{ int i; var j = (i = true) ${op} 2; }", |
| 576 warnings: [NOT_ASSIGNABLE, MessageKind.OPERATOR_NOT_FOUND]); | 576 warnings: [NOT_ASSIGNABLE, MessageKind.UNDEFINED_OPERATOR]); |
| 577 check("{ int i; var j = 1 ${op} (i = true); }", | 577 check("{ int i; var j = 1 ${op} (i = true); }", |
| 578 warnings: [NOT_ASSIGNABLE, NOT_ASSIGNABLE]); | 578 warnings: [NOT_ASSIGNABLE, NOT_ASSIGNABLE]); |
| 579 } | 579 } |
| 580 for (final op in ['-', '~']) { | 580 for (final op in ['-', '~']) { |
| 581 check("{ var i = ${op}1; }"); | 581 check("{ var i = ${op}1; }"); |
| 582 check("{ int i; var j = ${op}(i = true); }", | 582 check("{ int i; var j = ${op}(i = true); }", |
| 583 warnings: [NOT_ASSIGNABLE, MessageKind.OPERATOR_NOT_FOUND]); | 583 warnings: [NOT_ASSIGNABLE, MessageKind.UNDEFINED_OPERATOR]); |
| 584 } | 584 } |
| 585 for (final op in ['++', '--']) { | 585 for (final op in ['++', '--']) { |
| 586 check("{ int i = 1; int j = i${op}; }"); | 586 check("{ int i = 1; int j = i${op}; }"); |
| 587 check("{ int i = 1; bool j = i${op}; }", warnings: NOT_ASSIGNABLE); | 587 check("{ int i = 1; bool j = i${op}; }", warnings: NOT_ASSIGNABLE); |
| 588 check("{ bool b = true; bool j = b${op}; }", | 588 check("{ bool b = true; bool j = b${op}; }", |
| 589 warnings: MessageKind.OPERATOR_NOT_FOUND); | 589 warnings: MessageKind.UNDEFINED_OPERATOR); |
| 590 check("{ bool b = true; int j = ${op}b; }", | 590 check("{ bool b = true; int j = ${op}b; }", |
| 591 warnings: MessageKind.OPERATOR_NOT_FOUND); | 591 warnings: MessageKind.UNDEFINED_OPERATOR); |
| 592 } | 592 } |
| 593 for (final op in ['||', '&&']) { | 593 for (final op in ['||', '&&']) { |
| 594 check("{ bool b = (true ${op} false); }"); | 594 check("{ bool b = (true ${op} false); }"); |
| 595 check("{ int b = true ${op} false; }", warnings: NOT_ASSIGNABLE); | 595 check("{ int b = true ${op} false; }", warnings: NOT_ASSIGNABLE); |
| 596 check("{ bool b = (1 ${op} false); }", warnings: NOT_ASSIGNABLE); | 596 check("{ bool b = (1 ${op} false); }", warnings: NOT_ASSIGNABLE); |
| 597 check("{ bool b = (true ${op} 2); }", warnings: NOT_ASSIGNABLE); | 597 check("{ bool b = (true ${op} 2); }", warnings: NOT_ASSIGNABLE); |
| 598 } | 598 } |
| 599 for (final op in ['>', '<', '<=', '>=']) { | 599 for (final op in ['>', '<', '<=', '>=']) { |
| 600 check("{ bool b = 1 ${op} 2; }"); | 600 check("{ bool b = 1 ${op} 2; }"); |
| 601 check("{ int i = 1 ${op} 2; }", warnings: NOT_ASSIGNABLE); | 601 check("{ int i = 1 ${op} 2; }", warnings: NOT_ASSIGNABLE); |
| 602 check("{ int i; bool b = (i = true) ${op} 2; }", | 602 check("{ int i; bool b = (i = true) ${op} 2; }", |
| 603 warnings: [NOT_ASSIGNABLE, MessageKind.OPERATOR_NOT_FOUND]); | 603 warnings: [NOT_ASSIGNABLE, MessageKind.UNDEFINED_OPERATOR]); |
| 604 check("{ int i; bool b = 1 ${op} (i = true); }", | 604 check("{ int i; bool b = 1 ${op} (i = true); }", |
| 605 warnings: [NOT_ASSIGNABLE, NOT_ASSIGNABLE]); | 605 warnings: [NOT_ASSIGNABLE, NOT_ASSIGNABLE]); |
| 606 } | 606 } |
| 607 for (final op in ['==', '!=']) { | 607 for (final op in ['==', '!=']) { |
| 608 check("{ bool b = 1 ${op} 2; }"); | 608 check("{ bool b = 1 ${op} 2; }"); |
| 609 check("{ int i = 1 ${op} 2; }", warnings: NOT_ASSIGNABLE); | 609 check("{ int i = 1 ${op} 2; }", warnings: NOT_ASSIGNABLE); |
| 610 check("{ int i; bool b = (i = true) ${op} 2; }", | 610 check("{ int i; bool b = (i = true) ${op} 2; }", |
| 611 warnings: NOT_ASSIGNABLE); | 611 warnings: NOT_ASSIGNABLE); |
| 612 check("{ int i; bool b = 1 ${op} (i = true); }", | 612 check("{ int i; bool b = 1 ${op} (i = true); }", |
| 613 warnings: NOT_ASSIGNABLE); | 613 warnings: NOT_ASSIGNABLE); |
| (...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 998 check(c, "localMethod();", MessageKind.MISSING_ARGUMENT); | 998 check(c, "localMethod();", MessageKind.MISSING_ARGUMENT); |
| 999 check(c, "localMethod(1);", NOT_ASSIGNABLE); | 999 check(c, "localMethod(1);", NOT_ASSIGNABLE); |
| 1000 check(c, "localMethod('string');"); | 1000 check(c, "localMethod('string');"); |
| 1001 check(c, "int k = localMethod('string');"); | 1001 check(c, "int k = localMethod('string');"); |
| 1002 check(c, "String k = localMethod('string');", NOT_ASSIGNABLE); | 1002 check(c, "String k = localMethod('string');", NOT_ASSIGNABLE); |
| 1003 | 1003 |
| 1004 // Invocation on parenthesized expressions. | 1004 // Invocation on parenthesized expressions. |
| 1005 check(c, "(e)();"); | 1005 check(c, "(e)();"); |
| 1006 check(c, "(e)(1);"); | 1006 check(c, "(e)(1);"); |
| 1007 check(c, "(e)('string');"); | 1007 check(c, "(e)('string');"); |
| 1008 check(c, "(foo)();", MEMBER_NOT_FOUND); | 1008 check(c, "(foo)();", UNDEFINED_GETTER); |
| 1009 check(c, "(foo)(1);", MEMBER_NOT_FOUND); | 1009 check(c, "(foo)(1);", UNDEFINED_GETTER); |
| 1010 check(c, "(foo)('string');", MEMBER_NOT_FOUND); | 1010 check(c, "(foo)('string');", UNDEFINED_GETTER); |
| 1011 | 1011 |
| 1012 // Invocations on function expressions. | 1012 // Invocations on function expressions. |
| 1013 check(c, "(foo){}();", MessageKind.MISSING_ARGUMENT); | 1013 check(c, "(foo){}();", MessageKind.MISSING_ARGUMENT); |
| 1014 check(c, "(foo){}(1);"); | 1014 check(c, "(foo){}(1);"); |
| 1015 check(c, "(foo){}('string');"); | 1015 check(c, "(foo){}('string');"); |
| 1016 check(c, "(int foo){}('string');", NOT_ASSIGNABLE); | 1016 check(c, "(int foo){}('string');", NOT_ASSIGNABLE); |
| 1017 check(c, "(String foo){}('string');"); | 1017 check(c, "(String foo){}('string');"); |
| 1018 check(c, "int k = int bar(String foo){ return 0; }('string');"); | 1018 check(c, "int k = int bar(String foo){ return 0; }('string');"); |
| 1019 check(c, "int k = String bar(String foo){ return foo; }('string');", | 1019 check(c, "int k = String bar(String foo){ return foo; }('string');", |
| 1020 NOT_ASSIGNABLE); | 1020 NOT_ASSIGNABLE); |
| 1021 | 1021 |
| 1022 // Static invocations. | 1022 // Static invocations. |
| 1023 check(c, "staticMethod();", | 1023 check(c, "staticMethod();", |
| 1024 MessageKind.MISSING_ARGUMENT); | 1024 MessageKind.MISSING_ARGUMENT); |
| 1025 check(c, "staticMethod(1);", | 1025 check(c, "staticMethod(1);", |
| 1026 NOT_ASSIGNABLE); | 1026 NOT_ASSIGNABLE); |
| 1027 check(c, "staticMethod('string');"); | 1027 check(c, "staticMethod('string');"); |
| 1028 check(c, "int k = staticMethod('string');"); | 1028 check(c, "int k = staticMethod('string');"); |
| 1029 check(c, "String k = staticMethod('string');", | 1029 check(c, "String k = staticMethod('string');", |
| 1030 NOT_ASSIGNABLE); | 1030 NOT_ASSIGNABLE); |
| 1031 check(d, "staticMethod();", MessageKind.METHOD_NOT_FOUND); | 1031 check(d, "staticMethod();", MessageKind.UNDEFINED_METHOD); |
| 1032 check(d, "staticMethod(1);", MessageKind.METHOD_NOT_FOUND); | 1032 check(d, "staticMethod(1);", MessageKind.UNDEFINED_METHOD); |
| 1033 check(d, "staticMethod('string');", MessageKind.METHOD_NOT_FOUND); | 1033 check(d, "staticMethod('string');", MessageKind.UNDEFINED_METHOD); |
| 1034 check(d, "int k = staticMethod('string');", MessageKind.METHOD_NOT_FOUND); | 1034 check(d, "int k = staticMethod('string');", MessageKind.UNDEFINED_METHOD); |
| 1035 check(d, "String k = staticMethod('string');", MessageKind.METHOD_NOT_FOUND)
; | 1035 check(d, "String k = staticMethod('string');", MessageKind.UNDEFINED_METHOD)
; |
| 1036 | 1036 |
| 1037 // Invocation on dynamic variable. | 1037 // Invocation on dynamic variable. |
| 1038 check(c, "e.foo();"); | 1038 check(c, "e.foo();"); |
| 1039 check(c, "e.foo(1);"); | 1039 check(c, "e.foo(1);"); |
| 1040 check(c, "e.foo('string');"); | 1040 check(c, "e.foo('string');"); |
| 1041 | 1041 |
| 1042 // Invocation on unresolved variable. | 1042 // Invocation on unresolved variable. |
| 1043 check(c, "foo();", MessageKind.METHOD_NOT_FOUND); | 1043 check(c, "foo();", MessageKind.UNDEFINED_METHOD); |
| 1044 check(c, "foo(1);", MessageKind.METHOD_NOT_FOUND); | 1044 check(c, "foo(1);", MessageKind.UNDEFINED_METHOD); |
| 1045 check(c, "foo('string');", MessageKind.METHOD_NOT_FOUND); | 1045 check(c, "foo('string');", MessageKind.UNDEFINED_METHOD); |
| 1046 check(c, "foo(a: 'string');", MessageKind.METHOD_NOT_FOUND); | 1046 check(c, "foo(a: 'string');", MessageKind.UNDEFINED_METHOD); |
| 1047 check(c, "foo(a: localMethod(1));", | 1047 check(c, "foo(a: localMethod(1));", |
| 1048 [MessageKind.METHOD_NOT_FOUND, NOT_ASSIGNABLE]); | 1048 [MessageKind.UNDEFINED_METHOD, NOT_ASSIGNABLE]); |
| 1049 }); | 1049 }); |
| 1050 } | 1050 } |
| 1051 | 1051 |
| 1052 void testFunctionCall(MockCompiler compiler) { | 1052 void testFunctionCall(MockCompiler compiler) { |
| 1053 compiler.parseScript(CLASS_WITH_METHODS); | 1053 compiler.parseScript(CLASS_WITH_METHODS); |
| 1054 | 1054 |
| 1055 check(String text, [expectedWarnings]){ | 1055 check(String text, [expectedWarnings]){ |
| 1056 analyze(compiler, | 1056 analyze(compiler, |
| 1057 """{ | 1057 """{ |
| 1058 ClassWithMethods x; | 1058 ClassWithMethods x; |
| (...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1519 compiler.parseScript(script); | 1519 compiler.parseScript(script); |
| 1520 ClassElement foo = compiler.mainApp.find("Foo"); | 1520 ClassElement foo = compiler.mainApp.find("Foo"); |
| 1521 foo.ensureResolved(compiler.resolution); | 1521 foo.ensureResolved(compiler.resolution); |
| 1522 Element method = foo.lookupLocalMember('method'); | 1522 Element method = foo.lookupLocalMember('method'); |
| 1523 | 1523 |
| 1524 analyzeIn(compiler, method, "{ Type type = T; }"); | 1524 analyzeIn(compiler, method, "{ Type type = T; }"); |
| 1525 analyzeIn(compiler, method, "{ T type = T; }", warnings: NOT_ASSIGNABLE); | 1525 analyzeIn(compiler, method, "{ T type = T; }", warnings: NOT_ASSIGNABLE); |
| 1526 analyzeIn(compiler, method, "{ int type = T; }", warnings: NOT_ASSIGNABLE); | 1526 analyzeIn(compiler, method, "{ int type = T; }", warnings: NOT_ASSIGNABLE); |
| 1527 | 1527 |
| 1528 analyzeIn(compiler, method, "{ String typeName = T.toString(); }"); | 1528 analyzeIn(compiler, method, "{ String typeName = T.toString(); }"); |
| 1529 analyzeIn(compiler, method, "{ T.foo; }", warnings: MEMBER_NOT_FOUND); | 1529 analyzeIn(compiler, method, "{ T.foo; }", warnings: UNDEFINED_GETTER); |
| 1530 analyzeIn(compiler, method, "{ T.foo = 0; }", | 1530 analyzeIn(compiler, method, "{ T.foo = 0; }", |
| 1531 warnings: MessageKind.SETTER_NOT_FOUND); | 1531 warnings: MessageKind.UNDEFINED_SETTER); |
| 1532 analyzeIn(compiler, method, "{ T.foo(); }", | 1532 analyzeIn(compiler, method, "{ T.foo(); }", |
| 1533 warnings: MessageKind.METHOD_NOT_FOUND); | 1533 warnings: MessageKind.UNDEFINED_METHOD); |
| 1534 analyzeIn(compiler, method, "{ T + 1; }", | 1534 analyzeIn(compiler, method, "{ T + 1; }", |
| 1535 warnings: MessageKind.OPERATOR_NOT_FOUND); | 1535 warnings: MessageKind.UNDEFINED_OPERATOR); |
| 1536 } | 1536 } |
| 1537 | 1537 |
| 1538 void testTypeVariableLookup1(MockCompiler compiler) { | 1538 void testTypeVariableLookup1(MockCompiler compiler) { |
| 1539 String script = """ | 1539 String script = """ |
| 1540 class Foo { | 1540 class Foo { |
| 1541 int field; | 1541 int field; |
| 1542 void method(int argument) {} | 1542 void method(int argument) {} |
| 1543 int operator +(Foo foo) {} | 1543 int operator +(Foo foo) {} |
| 1544 int get getter => 21; | 1544 int get getter => 21; |
| 1545 } | 1545 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1559 test(String expression, [message]) { | 1559 test(String expression, [message]) { |
| 1560 analyzeIn(compiler, methodTest, "{ $expression; }", warnings: message); | 1560 analyzeIn(compiler, methodTest, "{ $expression; }", warnings: message); |
| 1561 } | 1561 } |
| 1562 | 1562 |
| 1563 test('s.field'); | 1563 test('s.field'); |
| 1564 test('s.method(1)'); | 1564 test('s.method(1)'); |
| 1565 test('s + s'); | 1565 test('s + s'); |
| 1566 test('s.getter'); | 1566 test('s.getter'); |
| 1567 | 1567 |
| 1568 test('t.toString'); | 1568 test('t.toString'); |
| 1569 test('t.field', MEMBER_NOT_FOUND); | 1569 test('t.field', UNDEFINED_GETTER); |
| 1570 test('t.method(1)', MessageKind.METHOD_NOT_FOUND); | 1570 test('t.method(1)', MessageKind.UNDEFINED_METHOD); |
| 1571 test('t + t', MessageKind.OPERATOR_NOT_FOUND); | 1571 test('t + t', MessageKind.UNDEFINED_OPERATOR); |
| 1572 test('t.getter', MEMBER_NOT_FOUND); | 1572 test('t.getter', UNDEFINED_GETTER); |
| 1573 | 1573 |
| 1574 test('s.field = "hest"', NOT_ASSIGNABLE); | 1574 test('s.field = "hest"', NOT_ASSIGNABLE); |
| 1575 test('s.method("hest")', NOT_ASSIGNABLE); | 1575 test('s.method("hest")', NOT_ASSIGNABLE); |
| 1576 test('s + "hest"', NOT_ASSIGNABLE); | 1576 test('s + "hest"', NOT_ASSIGNABLE); |
| 1577 test('String v = s.getter', NOT_ASSIGNABLE); | 1577 test('String v = s.getter', NOT_ASSIGNABLE); |
| 1578 } | 1578 } |
| 1579 | 1579 |
| 1580 void testTypeVariableLookup2(MockCompiler compiler) { | 1580 void testTypeVariableLookup2(MockCompiler compiler) { |
| 1581 String script = """ | 1581 String script = """ |
| 1582 class Foo { | 1582 class Foo { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1616 compiler.parseScript(script); | 1616 compiler.parseScript(script); |
| 1617 ClassElement classTest = compiler.mainApp.find("Test"); | 1617 ClassElement classTest = compiler.mainApp.find("Test"); |
| 1618 classTest.ensureResolved(compiler.resolution); | 1618 classTest.ensureResolved(compiler.resolution); |
| 1619 FunctionElement methodTest = classTest.lookupLocalMember("test"); | 1619 FunctionElement methodTest = classTest.lookupLocalMember("test"); |
| 1620 | 1620 |
| 1621 test(String expression, [message]) { | 1621 test(String expression, [message]) { |
| 1622 analyzeIn(compiler, methodTest, "{ $expression; }", warnings: message); | 1622 analyzeIn(compiler, methodTest, "{ $expression; }", warnings: message); |
| 1623 } | 1623 } |
| 1624 | 1624 |
| 1625 test('s.toString'); | 1625 test('s.toString'); |
| 1626 test('s.field', MEMBER_NOT_FOUND); | 1626 test('s.field', UNDEFINED_GETTER); |
| 1627 test('s.method(1)', MessageKind.METHOD_NOT_FOUND); | 1627 test('s.method(1)', MessageKind.UNDEFINED_METHOD); |
| 1628 test('s + s', MessageKind.OPERATOR_NOT_FOUND); | 1628 test('s + s', MessageKind.UNDEFINED_OPERATOR); |
| 1629 test('s.getter', MEMBER_NOT_FOUND); | 1629 test('s.getter', UNDEFINED_GETTER); |
| 1630 } | 1630 } |
| 1631 | 1631 |
| 1632 void testFunctionTypeLookup(MockCompiler compiler) { | 1632 void testFunctionTypeLookup(MockCompiler compiler) { |
| 1633 check(String code, {warnings}) { | 1633 check(String code, {warnings}) { |
| 1634 analyze(compiler, code, warnings: warnings); | 1634 analyze(compiler, code, warnings: warnings); |
| 1635 } | 1635 } |
| 1636 | 1636 |
| 1637 check('(int f(int)) => f.toString;'); | 1637 check('(int f(int)) => f.toString;'); |
| 1638 check('(int f(int)) => f.toString();'); | 1638 check('(int f(int)) => f.toString();'); |
| 1639 check('(int f(int)) => f.foo;', warnings: MEMBER_NOT_FOUND); | 1639 check('(int f(int)) => f.foo;', warnings: UNDEFINED_GETTER); |
| 1640 check('(int f(int)) => f.foo();', warnings: MessageKind.METHOD_NOT_FOUND); | 1640 check('(int f(int)) => f.foo();', warnings: MessageKind.UNDEFINED_METHOD); |
| 1641 } | 1641 } |
| 1642 | 1642 |
| 1643 void testTypedefLookup(MockCompiler compiler) { | 1643 void testTypedefLookup(MockCompiler compiler) { |
| 1644 check(String code, {warnings}) { | 1644 check(String code, {warnings}) { |
| 1645 analyze(compiler, code, warnings: warnings); | 1645 analyze(compiler, code, warnings: warnings); |
| 1646 } | 1646 } |
| 1647 | 1647 |
| 1648 compiler.parseScript("typedef int F(int);"); | 1648 compiler.parseScript("typedef int F(int);"); |
| 1649 check('(F f) => f.toString;'); | 1649 check('(F f) => f.toString;'); |
| 1650 check('(F f) => f.toString();'); | 1650 check('(F f) => f.toString();'); |
| 1651 check('(F f) => f.foo;', warnings: MEMBER_NOT_FOUND); | 1651 check('(F f) => f.foo;', warnings: UNDEFINED_GETTER); |
| 1652 check('(F f) => f.foo();', warnings: MessageKind.METHOD_NOT_FOUND); | 1652 check('(F f) => f.foo();', warnings: MessageKind.UNDEFINED_METHOD); |
| 1653 } | 1653 } |
| 1654 | 1654 |
| 1655 void testTypeLiteral(MockCompiler compiler) { | 1655 void testTypeLiteral(MockCompiler compiler) { |
| 1656 check(String code, {warnings}) { | 1656 check(String code, {warnings}) { |
| 1657 analyze(compiler, code, warnings: warnings); | 1657 analyze(compiler, code, warnings: warnings); |
| 1658 } | 1658 } |
| 1659 | 1659 |
| 1660 final String source = r"""class Class { | 1660 final String source = r"""class Class { |
| 1661 static var field = null; | 1661 static var field = null; |
| 1662 static method() {} | 1662 static method() {} |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1676 // Check access as argument. | 1676 // Check access as argument. |
| 1677 check('m(Type val) => m(int);'); | 1677 check('m(Type val) => m(int);'); |
| 1678 check('m(int val) => m(int);', warnings: NOT_ASSIGNABLE); | 1678 check('m(int val) => m(int);', warnings: NOT_ASSIGNABLE); |
| 1679 | 1679 |
| 1680 // Check access as argument in member access. | 1680 // Check access as argument in member access. |
| 1681 check('m(Type val) => m(int).foo;'); | 1681 check('m(Type val) => m(int).foo;'); |
| 1682 check('m(int val) => m(int).foo;', warnings: NOT_ASSIGNABLE); | 1682 check('m(int val) => m(int).foo;', warnings: NOT_ASSIGNABLE); |
| 1683 | 1683 |
| 1684 // Check static property access. | 1684 // Check static property access. |
| 1685 check('m() => Class.field;'); | 1685 check('m() => Class.field;'); |
| 1686 check('m() => (Class).field;', warnings: MEMBER_NOT_FOUND); | 1686 check('m() => (Class).field;', warnings: UNDEFINED_GETTER); |
| 1687 | 1687 |
| 1688 // Check static method access. | 1688 // Check static method access. |
| 1689 check('m() => Class.method();'); | 1689 check('m() => Class.method();'); |
| 1690 check('m() => (Class).method();', warnings: MessageKind.METHOD_NOT_FOUND); | 1690 check('m() => (Class).method();', warnings: MessageKind.UNDEFINED_METHOD); |
| 1691 | 1691 |
| 1692 // Check access in invocation. | 1692 // Check access in invocation. |
| 1693 check('m() => Class();', warnings: MessageKind.NOT_CALLABLE); | 1693 check('m() => Class();', warnings: MessageKind.NOT_CALLABLE); |
| 1694 check('m() => dynamic();', warnings: MessageKind.NOT_CALLABLE); | 1694 check('m() => dynamic();', warnings: MessageKind.NOT_CALLABLE); |
| 1695 } | 1695 } |
| 1696 | 1696 |
| 1697 Future testInitializers(MockCompiler compiler) { | 1697 Future testInitializers(MockCompiler compiler) { |
| 1698 Future check(String text, [expectedWarnings]) { | 1698 Future check(String text, [expectedWarnings]) { |
| 1699 return analyzeTopLevel(text, expectedWarnings); | 1699 return analyzeTopLevel(text, expectedWarnings); |
| 1700 } | 1700 } |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1949 check("Class.staticField += 0;", NOT_ASSIGNABLE); | 1949 check("Class.staticField += 0;", NOT_ASSIGNABLE); |
| 1950 // String is not assignable to int (the argument type of the operator + on the | 1950 // String is not assignable to int (the argument type of the operator + on the |
| 1951 // getter) and num (the result type of the operation) is not assignable to | 1951 // getter) and num (the result type of the operation) is not assignable to |
| 1952 // String (the type of the setter). | 1952 // String (the type of the setter). |
| 1953 check("Class.staticField += '';", | 1953 check("Class.staticField += '';", |
| 1954 [NOT_ASSIGNABLE, NOT_ASSIGNABLE]); | 1954 [NOT_ASSIGNABLE, NOT_ASSIGNABLE]); |
| 1955 | 1955 |
| 1956 check("int v = c.overriddenField;"); | 1956 check("int v = c.overriddenField;"); |
| 1957 check("c.overriddenField = 0;"); | 1957 check("c.overriddenField = 0;"); |
| 1958 check("int v = c.getterField;"); | 1958 check("int v = c.getterField;"); |
| 1959 check("c.getterField = 0;", MessageKind.SETTER_NOT_FOUND); | 1959 check("c.getterField = 0;", MessageKind.UNDEFINED_SETTER); |
| 1960 check("int v = c.setterField;", MessageKind.GETTER_NOT_FOUND); | 1960 check("int v = c.setterField;", |
| 1961 MessageKind.UNDEFINED_INSTANCE_GETTER_BUT_SETTER); |
| 1961 check("c.setterField = 0;"); | 1962 check("c.setterField = 0;"); |
| 1962 | 1963 |
| 1963 check("int v = gc.overriddenField;"); | 1964 check("int v = gc.overriddenField;"); |
| 1964 check("gc.overriddenField = 0;"); | 1965 check("gc.overriddenField = 0;"); |
| 1965 check("int v = gc.setterField;"); | 1966 check("int v = gc.setterField;"); |
| 1966 check("gc.setterField = 0;"); | 1967 check("gc.setterField = 0;"); |
| 1967 check("int v = gc.getterField;"); | 1968 check("int v = gc.getterField;"); |
| 1968 check("gc.getterField = 0;", MessageKind.SETTER_NOT_FOUND); | 1969 check("gc.getterField = 0;", MessageKind.UNDEFINED_SETTER); |
| 1969 | 1970 |
| 1970 check("int v = sc.overriddenField;"); | 1971 check("int v = sc.overriddenField;"); |
| 1971 check("sc.overriddenField = 0;"); | 1972 check("sc.overriddenField = 0;"); |
| 1972 check("int v = sc.getterField;"); | 1973 check("int v = sc.getterField;"); |
| 1973 check("sc.getterField = 0;"); | 1974 check("sc.getterField = 0;"); |
| 1974 check("int v = sc.setterField;", MessageKind.GETTER_NOT_FOUND); | 1975 check("int v = sc.setterField;", |
| 1976 MessageKind.UNDEFINED_INSTANCE_GETTER_BUT_SETTER); |
| 1975 check("sc.setterField = 0;"); | 1977 check("sc.setterField = 0;"); |
| 1976 } | 1978 } |
| 1977 | 1979 |
| 1978 testTypePromotionHints(MockCompiler compiler) { | 1980 testTypePromotionHints(MockCompiler compiler) { |
| 1979 compiler.parseScript(r'''class A { | 1981 compiler.parseScript(r'''class A { |
| 1980 var a = "a"; | 1982 var a = "a"; |
| 1981 } | 1983 } |
| 1982 class B extends A { | 1984 class B extends A { |
| 1983 var b = "b"; | 1985 var b = "b"; |
| 1984 } | 1986 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 2005 warnings: warnings, | 2007 warnings: warnings, |
| 2006 hints: hints, | 2008 hints: hints, |
| 2007 infos: infos); | 2009 infos: infos); |
| 2008 } | 2010 } |
| 2009 | 2011 |
| 2010 check(r''' | 2012 check(r''' |
| 2011 A a = new B(); | 2013 A a = new B(); |
| 2012 if (a is C) { | 2014 if (a is C) { |
| 2013 var x = a.c; | 2015 var x = a.c; |
| 2014 }''', | 2016 }''', |
| 2015 warnings: [MessageKind.MEMBER_NOT_FOUND], | 2017 warnings: [MessageKind.UNDEFINED_GETTER], |
| 2016 hints: [MessageKind.NOT_MORE_SPECIFIC_SUBTYPE], | 2018 hints: [MessageKind.NOT_MORE_SPECIFIC_SUBTYPE], |
| 2017 infos: []); | 2019 infos: []); |
| 2018 | 2020 |
| 2019 check(r''' | 2021 check(r''' |
| 2020 A a = new B(); | 2022 A a = new B(); |
| 2021 if (a is C) { | 2023 if (a is C) { |
| 2022 var x = '${a.c}${a.c}'; | 2024 var x = '${a.c}${a.c}'; |
| 2023 }''', | 2025 }''', |
| 2024 warnings: [MessageKind.MEMBER_NOT_FOUND, | 2026 warnings: [MessageKind.UNDEFINED_GETTER, |
| 2025 MessageKind.MEMBER_NOT_FOUND], | 2027 MessageKind.UNDEFINED_GETTER], |
| 2026 hints: [MessageKind.NOT_MORE_SPECIFIC_SUBTYPE], | 2028 hints: [MessageKind.NOT_MORE_SPECIFIC_SUBTYPE], |
| 2027 infos: []); | 2029 infos: []); |
| 2028 | 2030 |
| 2029 check(r''' | 2031 check(r''' |
| 2030 A a = new B(); | 2032 A a = new B(); |
| 2031 if (a is C) { | 2033 if (a is C) { |
| 2032 var x = '${a.d}${a.d}'; // Type promotion wouldn't help. | 2034 var x = '${a.d}${a.d}'; // Type promotion wouldn't help. |
| 2033 }''', | 2035 }''', |
| 2034 warnings: [MessageKind.MEMBER_NOT_FOUND, | 2036 warnings: [MessageKind.UNDEFINED_GETTER, |
| 2035 MessageKind.MEMBER_NOT_FOUND], | 2037 MessageKind.UNDEFINED_GETTER], |
| 2036 hints: [], | 2038 hints: [], |
| 2037 infos: []); | 2039 infos: []); |
| 2038 | 2040 |
| 2039 check(''' | 2041 check(''' |
| 2040 D<int> d = new E(); | 2042 D<int> d = new E(); |
| 2041 if (d is E) { // Suggest E<int>. | 2043 if (d is E) { // Suggest E<int>. |
| 2042 var x = d.e; | 2044 var x = d.e; |
| 2043 }''', | 2045 }''', |
| 2044 warnings: [MessageKind.MEMBER_NOT_FOUND], | 2046 warnings: [MessageKind.UNDEFINED_GETTER], |
| 2045 hints: [checkMessage(MessageKind.NOT_MORE_SPECIFIC_SUGGESTION, | 2047 hints: [checkMessage(MessageKind.NOT_MORE_SPECIFIC_SUGGESTION, |
| 2046 {'shownTypeSuggestion': 'E<int>'})], | 2048 {'shownTypeSuggestion': 'E<int>'})], |
| 2047 infos: []); | 2049 infos: []); |
| 2048 | 2050 |
| 2049 check(''' | 2051 check(''' |
| 2050 D<int> d = new F(); | 2052 D<int> d = new F(); |
| 2051 if (d is F) { // Suggest F<int, dynamic>. | 2053 if (d is F) { // Suggest F<int, dynamic>. |
| 2052 var x = d.f; | 2054 var x = d.f; |
| 2053 }''', | 2055 }''', |
| 2054 warnings: [MessageKind.MEMBER_NOT_FOUND], | 2056 warnings: [MessageKind.UNDEFINED_GETTER], |
| 2055 hints: [checkMessage(MessageKind.NOT_MORE_SPECIFIC_SUGGESTION, | 2057 hints: [checkMessage(MessageKind.NOT_MORE_SPECIFIC_SUGGESTION, |
| 2056 {'shownTypeSuggestion': 'F<int, dynamic>'})], | 2058 {'shownTypeSuggestion': 'F<int, dynamic>'})], |
| 2057 infos: []); | 2059 infos: []); |
| 2058 | 2060 |
| 2059 check(''' | 2061 check(''' |
| 2060 D<int> d = new G(); | 2062 D<int> d = new G(); |
| 2061 if (d is G) { // Suggest G<int>. | 2063 if (d is G) { // Suggest G<int>. |
| 2062 var x = d.f; | 2064 var x = d.f; |
| 2063 }''', | 2065 }''', |
| 2064 warnings: [MessageKind.MEMBER_NOT_FOUND], | 2066 warnings: [MessageKind.UNDEFINED_GETTER], |
| 2065 hints: [checkMessage(MessageKind.NOT_MORE_SPECIFIC_SUGGESTION, | 2067 hints: [checkMessage(MessageKind.NOT_MORE_SPECIFIC_SUGGESTION, |
| 2066 {'shownTypeSuggestion': 'G<int>'})], | 2068 {'shownTypeSuggestion': 'G<int>'})], |
| 2067 infos: []); | 2069 infos: []); |
| 2068 | 2070 |
| 2069 check(''' | 2071 check(''' |
| 2070 F<double, int> f = new G(); | 2072 F<double, int> f = new G(); |
| 2071 if (f is G) { // Cannot suggest a more specific type. | 2073 if (f is G) { // Cannot suggest a more specific type. |
| 2072 var x = f.g; | 2074 var x = f.g; |
| 2073 }''', | 2075 }''', |
| 2074 warnings: [MessageKind.MEMBER_NOT_FOUND], | 2076 warnings: [MessageKind.UNDEFINED_GETTER], |
| 2075 hints: [MessageKind.NOT_MORE_SPECIFIC], | 2077 hints: [MessageKind.NOT_MORE_SPECIFIC], |
| 2076 infos: []); | 2078 infos: []); |
| 2077 | 2079 |
| 2078 check(''' | 2080 check(''' |
| 2079 D<int> d = new E(); | 2081 D<int> d = new E(); |
| 2080 if (d is E) { | 2082 if (d is E) { |
| 2081 var x = d.f; // Type promotion wouldn't help. | 2083 var x = d.f; // Type promotion wouldn't help. |
| 2082 }''', | 2084 }''', |
| 2083 warnings: [MessageKind.MEMBER_NOT_FOUND], | 2085 warnings: [MessageKind.UNDEFINED_GETTER], |
| 2084 hints: [], | 2086 hints: [], |
| 2085 infos: []); | 2087 infos: []); |
| 2086 | 2088 |
| 2087 check(''' | 2089 check(''' |
| 2088 A a = new B(); | 2090 A a = new B(); |
| 2089 if (a is B) { | 2091 if (a is B) { |
| 2090 a = null; | 2092 a = null; |
| 2091 var x = a.b; | 2093 var x = a.b; |
| 2092 }''', | 2094 }''', |
| 2093 warnings: [MessageKind.MEMBER_NOT_FOUND], | 2095 warnings: [MessageKind.UNDEFINED_GETTER], |
| 2094 hints: [MessageKind.POTENTIAL_MUTATION], | 2096 hints: [MessageKind.POTENTIAL_MUTATION], |
| 2095 infos: [MessageKind.POTENTIAL_MUTATION_HERE]); | 2097 infos: [MessageKind.POTENTIAL_MUTATION_HERE]); |
| 2096 | 2098 |
| 2097 check(''' | 2099 check(''' |
| 2098 A a = new B(); | 2100 A a = new B(); |
| 2099 if (a is B) { | 2101 if (a is B) { |
| 2100 a = null; | 2102 a = null; |
| 2101 var x = a.c; // Type promotion wouldn't help. | 2103 var x = a.c; // Type promotion wouldn't help. |
| 2102 }''', | 2104 }''', |
| 2103 warnings: [MessageKind.MEMBER_NOT_FOUND], | 2105 warnings: [MessageKind.UNDEFINED_GETTER], |
| 2104 hints: [], | 2106 hints: [], |
| 2105 infos: []); | 2107 infos: []); |
| 2106 | 2108 |
| 2107 check(''' | 2109 check(''' |
| 2108 A a = new B(); | 2110 A a = new B(); |
| 2109 local() { a = new A(); } | 2111 local() { a = new A(); } |
| 2110 if (a is B) { | 2112 if (a is B) { |
| 2111 var x = a.b; | 2113 var x = a.b; |
| 2112 }''', | 2114 }''', |
| 2113 warnings: [MessageKind.MEMBER_NOT_FOUND], | 2115 warnings: [MessageKind.UNDEFINED_GETTER], |
| 2114 hints: [MessageKind.POTENTIAL_MUTATION_IN_CLOSURE], | 2116 hints: [MessageKind.POTENTIAL_MUTATION_IN_CLOSURE], |
| 2115 infos: [MessageKind.POTENTIAL_MUTATION_IN_CLOSURE_HERE]); | 2117 infos: [MessageKind.POTENTIAL_MUTATION_IN_CLOSURE_HERE]); |
| 2116 | 2118 |
| 2117 check(''' | 2119 check(''' |
| 2118 A a = new B(); | 2120 A a = new B(); |
| 2119 local() { a = new A(); } | 2121 local() { a = new A(); } |
| 2120 if (a is B) { | 2122 if (a is B) { |
| 2121 var x = a.c; // Type promotion wouldn't help. | 2123 var x = a.c; // Type promotion wouldn't help. |
| 2122 }''', | 2124 }''', |
| 2123 warnings: [MessageKind.MEMBER_NOT_FOUND], | 2125 warnings: [MessageKind.UNDEFINED_GETTER], |
| 2124 hints: [], | 2126 hints: [], |
| 2125 infos: []); | 2127 infos: []); |
| 2126 | 2128 |
| 2127 check(''' | 2129 check(''' |
| 2128 A a = new B(); | 2130 A a = new B(); |
| 2129 if (a is B) { | 2131 if (a is B) { |
| 2130 var x = () => a; | 2132 var x = () => a; |
| 2131 var y = a.b; | 2133 var y = a.b; |
| 2132 } | 2134 } |
| 2133 a = new A();''', | 2135 a = new A();''', |
| 2134 warnings: [MessageKind.MEMBER_NOT_FOUND], | 2136 warnings: [MessageKind.UNDEFINED_GETTER], |
| 2135 hints: [MessageKind.ACCESSED_IN_CLOSURE], | 2137 hints: [MessageKind.ACCESSED_IN_CLOSURE], |
| 2136 infos: [MessageKind.ACCESSED_IN_CLOSURE_HERE, | 2138 infos: [MessageKind.ACCESSED_IN_CLOSURE_HERE, |
| 2137 MessageKind.POTENTIAL_MUTATION_HERE]); | 2139 MessageKind.POTENTIAL_MUTATION_HERE]); |
| 2138 | 2140 |
| 2139 check(''' | 2141 check(''' |
| 2140 A a = new B(); | 2142 A a = new B(); |
| 2141 if (a is B) { | 2143 if (a is B) { |
| 2142 var x = () => a; | 2144 var x = () => a; |
| 2143 var y = a.c; // Type promotion wouldn't help. | 2145 var y = a.c; // Type promotion wouldn't help. |
| 2144 } | 2146 } |
| 2145 a = new A();''', | 2147 a = new A();''', |
| 2146 warnings: [MessageKind.MEMBER_NOT_FOUND], | 2148 warnings: [MessageKind.UNDEFINED_GETTER], |
| 2147 hints: [], | 2149 hints: [], |
| 2148 infos: []); | 2150 infos: []); |
| 2149 } | 2151 } |
| 2150 | 2152 |
| 2151 void testCascade(MockCompiler compiler) { | 2153 void testCascade(MockCompiler compiler) { |
| 2152 compiler.parseScript(r'''typedef A AFunc(); | 2154 compiler.parseScript(r'''typedef A AFunc(); |
| 2153 typedef Function FuncFunc(); | 2155 typedef Function FuncFunc(); |
| 2154 class A { | 2156 class A { |
| 2155 A a; | 2157 A a; |
| 2156 B b; | 2158 B b; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2190 warnings: NOT_ASSIGNABLE); | 2192 warnings: NOT_ASSIGNABLE); |
| 2191 | 2193 |
| 2192 check('B b = new A()..b;', | 2194 check('B b = new A()..b;', |
| 2193 warnings: NOT_ASSIGNABLE); | 2195 warnings: NOT_ASSIGNABLE); |
| 2194 | 2196 |
| 2195 check('B b = new A().b;'); | 2197 check('B b = new A().b;'); |
| 2196 | 2198 |
| 2197 check('new A().b..b;'); | 2199 check('new A().b..b;'); |
| 2198 | 2200 |
| 2199 check('new A().b..a;', | 2201 check('new A().b..a;', |
| 2200 warnings: MEMBER_NOT_FOUND); | 2202 warnings: UNDEFINED_GETTER); |
| 2201 | 2203 |
| 2202 check('B b = new A().b..c;'); | 2204 check('B b = new A().b..c;'); |
| 2203 | 2205 |
| 2204 check('C c = new A().b..c;', | 2206 check('C c = new A().b..c;', |
| 2205 warnings: NOT_ASSIGNABLE); | 2207 warnings: NOT_ASSIGNABLE); |
| 2206 | 2208 |
| 2207 check('A a = new A()..a = new A();'); | 2209 check('A a = new A()..a = new A();'); |
| 2208 | 2210 |
| 2209 check('A a = new A()..b = new B();'); | 2211 check('A a = new A()..b = new B();'); |
| 2210 | 2212 |
| (...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2606 TreeElements elements = compiler.resolveNodeStatement(node, element); | 2608 TreeElements elements = compiler.resolveNodeStatement(node, element); |
| 2607 TypeCheckerVisitor checker = new TypeCheckerVisitor( | 2609 TypeCheckerVisitor checker = new TypeCheckerVisitor( |
| 2608 compiler, elements, compiler.types); | 2610 compiler, elements, compiler.types); |
| 2609 DiagnosticCollector collector = compiler.diagnosticCollector; | 2611 DiagnosticCollector collector = compiler.diagnosticCollector; |
| 2610 collector.clear(); | 2612 collector.clear(); |
| 2611 checker.analyze(node); | 2613 checker.analyze(node); |
| 2612 generateOutput(compiler, text); | 2614 generateOutput(compiler, text); |
| 2613 compareWarningKinds(text, warnings, collector.warnings); | 2615 compareWarningKinds(text, warnings, collector.warnings); |
| 2614 compareWarningKinds(text, hints, collector.hints); | 2616 compareWarningKinds(text, hints, collector.hints); |
| 2615 } | 2617 } |
| OLD | NEW |