| 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.resolver_test; | 5 library engine.resolver_test; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'package:analyzer/src/context/context.dart' as newContext; | 9 import 'package:analyzer/src/context/context.dart' as newContext; |
| 10 import 'package:analyzer/src/generated/ast.dart'; | 10 import 'package:analyzer/src/generated/ast.dart'; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 runReflectiveTests(TypeProviderImplTest); | 61 runReflectiveTests(TypeProviderImplTest); |
| 62 runReflectiveTests(TypeResolverVisitorTest); | 62 runReflectiveTests(TypeResolverVisitorTest); |
| 63 runReflectiveTests(CheckedModeCompileTimeErrorCodeTest); | 63 runReflectiveTests(CheckedModeCompileTimeErrorCodeTest); |
| 64 runReflectiveTests(ErrorResolverTest); | 64 runReflectiveTests(ErrorResolverTest); |
| 65 runReflectiveTests(HintCodeTest); | 65 runReflectiveTests(HintCodeTest); |
| 66 runReflectiveTests(MemberMapTest); | 66 runReflectiveTests(MemberMapTest); |
| 67 runReflectiveTests(NonHintCodeTest); | 67 runReflectiveTests(NonHintCodeTest); |
| 68 runReflectiveTests(SimpleResolverTest); | 68 runReflectiveTests(SimpleResolverTest); |
| 69 runReflectiveTests(StrictModeTest); | 69 runReflectiveTests(StrictModeTest); |
| 70 runReflectiveTests(TypePropagationTest); | 70 runReflectiveTests(TypePropagationTest); |
| 71 runReflectiveTests(StrongModeTypePropagationTest); |
| 71 } | 72 } |
| 72 | 73 |
| 73 /** | 74 /** |
| 74 * The class `AnalysisContextFactory` defines utility methods used to create ana
lysis contexts | 75 * The class `AnalysisContextFactory` defines utility methods used to create ana
lysis contexts |
| 75 * for testing purposes. | 76 * for testing purposes. |
| 76 */ | 77 */ |
| 77 class AnalysisContextFactory { | 78 class AnalysisContextFactory { |
| 78 static String _DART_MATH = "dart:math"; | 79 static String _DART_MATH = "dart:math"; |
| 79 | 80 |
| 80 static String _DART_INTERCEPTORS = "dart:_interceptors"; | 81 static String _DART_INTERCEPTORS = "dart:_interceptors"; |
| (...skipping 7965 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8046 return variable; | 8047 return variable; |
| 8047 } | 8048 } |
| 8048 } | 8049 } |
| 8049 } | 8050 } |
| 8050 } | 8051 } |
| 8051 return null; | 8052 return null; |
| 8052 // Not found | 8053 // Not found |
| 8053 } | 8054 } |
| 8054 | 8055 |
| 8055 /** | 8056 /** |
| 8057 * @param code the code that assigns the value to the variable "v", no matter
how. We check that |
| 8058 * "v" has expected static and propagated type. |
| 8059 */ |
| 8060 void _assertPropagatedAssignedType(String code, DartType expectedStaticType, |
| 8061 DartType expectedPropagatedType) { |
| 8062 SimpleIdentifier identifier = _findMarkedIdentifier(code, "v = "); |
| 8063 expect(identifier.staticType, same(expectedStaticType)); |
| 8064 expect(identifier.propagatedType, same(expectedPropagatedType)); |
| 8065 } |
| 8066 |
| 8067 /** |
| 8068 * Check the static and propagated types of the expression marked with "; // m
arker" comment. |
| 8069 * |
| 8070 * @param code source code to analyze, with the expression to check marked wit
h "// marker". |
| 8071 * @param expectedStaticType if non-null, check actual static type is equal to
this. |
| 8072 * @param expectedPropagatedType if non-null, check actual static type is equa
l to this. |
| 8073 * @throws Exception |
| 8074 */ |
| 8075 void _assertTypeOfMarkedExpression(String code, DartType expectedStaticType, |
| 8076 DartType expectedPropagatedType) { |
| 8077 SimpleIdentifier identifier = _findMarkedIdentifier(code, "; // marker"); |
| 8078 if (expectedStaticType != null) { |
| 8079 expect(identifier.staticType, expectedStaticType); |
| 8080 } |
| 8081 expect(identifier.propagatedType, expectedPropagatedType); |
| 8082 } |
| 8083 |
| 8084 /** |
| 8085 * Return the `SimpleIdentifier` marked by `marker`. The source code must have
no |
| 8086 * errors and be verifiable. |
| 8087 * |
| 8088 * @param code source code to analyze. |
| 8089 * @param marker marker identifying sought after expression in source code. |
| 8090 * @return expression marked by the marker. |
| 8091 * @throws Exception |
| 8092 */ |
| 8093 SimpleIdentifier _findMarkedIdentifier(String code, String marker) { |
| 8094 try { |
| 8095 Source source = addSource(code); |
| 8096 LibraryElement library = resolve2(source); |
| 8097 assertNoErrors(source); |
| 8098 verify([source]); |
| 8099 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 8100 // Could generalize this further by making [SimpleIdentifier.class] a |
| 8101 // parameter. |
| 8102 return EngineTestCase.findNode( |
| 8103 unit, code, marker, (node) => node is SimpleIdentifier); |
| 8104 } catch (exception) { |
| 8105 // Is there a better exception to throw here? The point is that an |
| 8106 // assertion failure here should be a failure, in both "test_*" and |
| 8107 // "fail_*" tests. However, an assertion failure is success for the |
| 8108 // purpose of "fail_*" tests, so without catching them here "fail_*" tests |
| 8109 // can succeed by failing for the wrong reason. |
| 8110 throw new JavaException("Unexexpected assertion failure: $exception"); |
| 8111 } |
| 8112 } |
| 8113 |
| 8114 /** |
| 8056 * In the rare cases we want to group several tests into single "test_" method
, so need a way to | 8115 * In the rare cases we want to group several tests into single "test_" method
, so need a way to |
| 8057 * reset test instance to reuse it. | 8116 * reset test instance to reuse it. |
| 8058 */ | 8117 */ |
| 8059 void reset() { | 8118 void reset() { |
| 8060 analysisContext2 = AnalysisContextFactory.contextWithCore(); | 8119 analysisContext2 = AnalysisContextFactory.contextWithCore(); |
| 8061 } | 8120 } |
| 8062 | 8121 |
| 8063 /** | 8122 /** |
| 8064 * Reset the analysis context to have the given options applied. | 8123 * Reset the analysis context to have the given options applied. |
| 8065 * | 8124 * |
| (...skipping 4133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12199 expect(typeProvider.intType.isSubtypeOf(t), isTrue); | 12258 expect(typeProvider.intType.isSubtypeOf(t), isTrue); |
| 12200 expect(typeProvider.stringType.isSubtypeOf(t), isTrue); | 12259 expect(typeProvider.stringType.isSubtypeOf(t), isTrue); |
| 12201 } | 12260 } |
| 12202 | 12261 |
| 12203 void fail_propagatedReturnType_functionExpression() { | 12262 void fail_propagatedReturnType_functionExpression() { |
| 12204 // TODO(scheglov) disabled because we don't resolve function expression | 12263 // TODO(scheglov) disabled because we don't resolve function expression |
| 12205 String code = r''' | 12264 String code = r''' |
| 12206 main() { | 12265 main() { |
| 12207 var v = (() {return 42;})(); | 12266 var v = (() {return 42;})(); |
| 12208 }'''; | 12267 }'''; |
| 12209 _assertPropagatedReturnType( | 12268 _assertPropagatedAssignedType( |
| 12210 code, typeProvider.dynamicType, typeProvider.intType); | 12269 code, typeProvider.dynamicType, typeProvider.intType); |
| 12211 } | 12270 } |
| 12212 | 12271 |
| 12213 void test_as() { | 12272 void test_as() { |
| 12214 Source source = addSource(r''' | 12273 Source source = addSource(r''' |
| 12215 class A { | 12274 class A { |
| 12216 bool get g => true; | 12275 bool get g => true; |
| 12217 } | 12276 } |
| 12218 A f(var p) { | 12277 A f(var p) { |
| 12219 if ((p as A).g) { | 12278 if ((p as A).g) { |
| (...skipping 1152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13372 null, | 13431 null, |
| 13373 typeProvider.stringType); | 13432 typeProvider.stringType); |
| 13374 } | 13433 } |
| 13375 | 13434 |
| 13376 void test_propagatedReturnType_function_hasReturnType_returnsNull() { | 13435 void test_propagatedReturnType_function_hasReturnType_returnsNull() { |
| 13377 String code = r''' | 13436 String code = r''' |
| 13378 String f() => null; | 13437 String f() => null; |
| 13379 main() { | 13438 main() { |
| 13380 var v = f(); | 13439 var v = f(); |
| 13381 }'''; | 13440 }'''; |
| 13382 _assertPropagatedReturnType( | 13441 _assertPropagatedAssignedType( |
| 13383 code, typeProvider.dynamicType, typeProvider.stringType); | 13442 code, typeProvider.dynamicType, typeProvider.stringType); |
| 13384 } | 13443 } |
| 13385 | 13444 |
| 13386 void test_propagatedReturnType_function_lessSpecificStaticReturnType() { | 13445 void test_propagatedReturnType_function_lessSpecificStaticReturnType() { |
| 13387 String code = r''' | 13446 String code = r''' |
| 13388 Object f() => 42; | 13447 Object f() => 42; |
| 13389 main() { | 13448 main() { |
| 13390 var v = f(); | 13449 var v = f(); |
| 13391 }'''; | 13450 }'''; |
| 13392 _assertPropagatedReturnType( | 13451 _assertPropagatedAssignedType( |
| 13393 code, typeProvider.dynamicType, typeProvider.intType); | 13452 code, typeProvider.dynamicType, typeProvider.intType); |
| 13394 } | 13453 } |
| 13395 | 13454 |
| 13396 void test_propagatedReturnType_function_moreSpecificStaticReturnType() { | 13455 void test_propagatedReturnType_function_moreSpecificStaticReturnType() { |
| 13397 String code = r''' | 13456 String code = r''' |
| 13398 int f(v) => (v as num); | 13457 int f(v) => (v as num); |
| 13399 main() { | 13458 main() { |
| 13400 var v = f(3); | 13459 var v = f(3); |
| 13401 }'''; | 13460 }'''; |
| 13402 _assertPropagatedReturnType( | 13461 _assertPropagatedAssignedType( |
| 13403 code, typeProvider.dynamicType, typeProvider.intType); | 13462 code, typeProvider.dynamicType, typeProvider.intType); |
| 13404 } | 13463 } |
| 13405 | 13464 |
| 13406 void test_propagatedReturnType_function_noReturnTypeName_blockBody_multipleRet
urns() { | 13465 void test_propagatedReturnType_function_noReturnTypeName_blockBody_multipleRet
urns() { |
| 13407 String code = r''' | 13466 String code = r''' |
| 13408 f() { | 13467 f() { |
| 13409 if (true) return 0; | 13468 if (true) return 0; |
| 13410 return 1.0; | 13469 return 1.0; |
| 13411 } | 13470 } |
| 13412 main() { | 13471 main() { |
| 13413 var v = f(); | 13472 var v = f(); |
| 13414 }'''; | 13473 }'''; |
| 13415 _assertPropagatedReturnType( | 13474 _assertPropagatedAssignedType( |
| 13416 code, typeProvider.dynamicType, typeProvider.numType); | 13475 code, typeProvider.dynamicType, typeProvider.numType); |
| 13417 } | 13476 } |
| 13418 | 13477 |
| 13419 void test_propagatedReturnType_function_noReturnTypeName_blockBody_oneReturn()
{ | 13478 void test_propagatedReturnType_function_noReturnTypeName_blockBody_oneReturn()
{ |
| 13420 String code = r''' | 13479 String code = r''' |
| 13421 f() { | 13480 f() { |
| 13422 var z = 42; | 13481 var z = 42; |
| 13423 return z; | 13482 return z; |
| 13424 } | 13483 } |
| 13425 main() { | 13484 main() { |
| 13426 var v = f(); | 13485 var v = f(); |
| 13427 }'''; | 13486 }'''; |
| 13428 _assertPropagatedReturnType( | 13487 _assertPropagatedAssignedType( |
| 13429 code, typeProvider.dynamicType, typeProvider.intType); | 13488 code, typeProvider.dynamicType, typeProvider.intType); |
| 13430 } | 13489 } |
| 13431 | 13490 |
| 13432 void test_propagatedReturnType_function_noReturnTypeName_expressionBody() { | 13491 void test_propagatedReturnType_function_noReturnTypeName_expressionBody() { |
| 13433 String code = r''' | 13492 String code = r''' |
| 13434 f() => 42; | 13493 f() => 42; |
| 13435 main() { | 13494 main() { |
| 13436 var v = f(); | 13495 var v = f(); |
| 13437 }'''; | 13496 }'''; |
| 13438 _assertPropagatedReturnType( | 13497 _assertPropagatedAssignedType( |
| 13439 code, typeProvider.dynamicType, typeProvider.intType); | 13498 code, typeProvider.dynamicType, typeProvider.intType); |
| 13440 } | 13499 } |
| 13441 | 13500 |
| 13442 void test_propagatedReturnType_localFunction() { | 13501 void test_propagatedReturnType_localFunction() { |
| 13443 String code = r''' | 13502 String code = r''' |
| 13444 main() { | 13503 main() { |
| 13445 f() => 42; | 13504 f() => 42; |
| 13446 var v = f(); | 13505 var v = f(); |
| 13447 }'''; | 13506 }'''; |
| 13448 _assertPropagatedReturnType( | 13507 _assertPropagatedAssignedType( |
| 13449 code, typeProvider.dynamicType, typeProvider.intType); | 13508 code, typeProvider.dynamicType, typeProvider.intType); |
| 13450 } | 13509 } |
| 13451 | 13510 |
| 13452 void test_query() { | 13511 void test_query() { |
| 13453 Source source = addSource(r''' | 13512 Source source = addSource(r''' |
| 13454 import 'dart:html'; | 13513 import 'dart:html'; |
| 13455 | 13514 |
| 13456 main() { | 13515 main() { |
| 13457 var v1 = query('a'); | 13516 var v1 = query('a'); |
| 13458 var v2 = query('A'); | 13517 var v2 = query('A'); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 13483 expect(elements[2].propagatedType.name, "BodyElement"); | 13542 expect(elements[2].propagatedType.name, "BodyElement"); |
| 13484 expect(elements[3].propagatedType.name, "ButtonElement"); | 13543 expect(elements[3].propagatedType.name, "ButtonElement"); |
| 13485 expect(elements[4].propagatedType.name, "DivElement"); | 13544 expect(elements[4].propagatedType.name, "DivElement"); |
| 13486 expect(elements[5].propagatedType.name, "InputElement"); | 13545 expect(elements[5].propagatedType.name, "InputElement"); |
| 13487 expect(elements[6].propagatedType.name, "SelectElement"); | 13546 expect(elements[6].propagatedType.name, "SelectElement"); |
| 13488 expect(elements[7].propagatedType.name, "DivElement"); | 13547 expect(elements[7].propagatedType.name, "DivElement"); |
| 13489 expect(elements[8].propagatedType.name, "Element"); | 13548 expect(elements[8].propagatedType.name, "Element"); |
| 13490 expect(elements[9].propagatedType.name, "Element"); | 13549 expect(elements[9].propagatedType.name, "Element"); |
| 13491 expect(elements[10].propagatedType.name, "Element"); | 13550 expect(elements[10].propagatedType.name, "Element"); |
| 13492 } | 13551 } |
| 13552 } |
| 13493 | 13553 |
| 13494 /** | 13554 @reflectiveTest |
| 13495 * @param code the code that assigns the value to the variable "v", no matter
how. We check that | 13555 class StrongModeTypePropagationTest extends ResolverTestCase { |
| 13496 * "v" has expected static and propagated type. | 13556 @override |
| 13497 */ | 13557 void setUp() { |
| 13498 void _assertPropagatedReturnType(String code, DartType expectedStaticType, | 13558 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); |
| 13499 DartType expectedPropagatedType) { | 13559 options.strongMode = true; |
| 13500 SimpleIdentifier identifier = _findMarkedIdentifier(code, "v = "); | 13560 resetWithOptions(options); |
| 13501 expect(identifier.staticType, same(expectedStaticType)); | |
| 13502 expect(identifier.propagatedType, same(expectedPropagatedType)); | |
| 13503 } | 13561 } |
| 13504 | 13562 |
| 13505 /** | 13563 void test_localVariableInference_constant() { |
| 13506 * Check the static and propagated types of the expression marked with "; // m
arker" comment. | 13564 String code = r''' |
| 13507 * | 13565 main() { |
| 13508 * @param code source code to analyze, with the expression to check marked wit
h "// marker". | 13566 var v = 3; |
| 13509 * @param expectedStaticType if non-null, check actual static type is equal to
this. | 13567 return v; // marker |
| 13510 * @param expectedPropagatedType if non-null, check actual static type is equa
l to this. | 13568 }'''; |
| 13511 * @throws Exception | 13569 _assertPropagatedAssignedType(code, typeProvider.intType, null); |
| 13512 */ | 13570 _assertTypeOfMarkedExpression(code, typeProvider.intType, null); |
| 13513 void _assertTypeOfMarkedExpression(String code, DartType expectedStaticType, | |
| 13514 DartType expectedPropagatedType) { | |
| 13515 SimpleIdentifier identifier = _findMarkedIdentifier(code, "; // marker"); | |
| 13516 if (expectedStaticType != null) { | |
| 13517 expect(identifier.staticType, expectedStaticType); | |
| 13518 } | |
| 13519 expect(identifier.propagatedType, expectedPropagatedType); | |
| 13520 } | 13571 } |
| 13521 | 13572 |
| 13522 /** | 13573 void test_localVariableInference_transitive_local() { |
| 13523 * Return the `SimpleIdentifier` marked by `marker`. The source code must have
no | 13574 String code = r''' |
| 13524 * errors and be verifiable. | 13575 main() { |
| 13525 * | 13576 var x = 3; |
| 13526 * @param code source code to analyze. | 13577 var v = x; |
| 13527 * @param marker marker identifying sought after expression in source code. | 13578 return v; // marker |
| 13528 * @return expression marked by the marker. | 13579 }'''; |
| 13529 * @throws Exception | 13580 _assertPropagatedAssignedType(code, typeProvider.intType, null); |
| 13530 */ | 13581 _assertTypeOfMarkedExpression(code, typeProvider.intType, null); |
| 13531 SimpleIdentifier _findMarkedIdentifier(String code, String marker) { | 13582 } |
| 13532 try { | 13583 |
| 13533 Source source = addSource(code); | 13584 void test_localVariableInference_transitive_list_local() { |
| 13534 LibraryElement library = resolve2(source); | 13585 String code = r''' |
| 13535 assertNoErrors(source); | 13586 main() { |
| 13536 verify([source]); | 13587 var x = <int>[3]; |
| 13537 CompilationUnit unit = resolveCompilationUnit(source, library); | 13588 var v = x[0]; |
| 13538 // Could generalize this further by making [SimpleIdentifier.class] a | 13589 return v; // marker |
| 13539 // parameter. | 13590 }'''; |
| 13540 return EngineTestCase.findNode( | 13591 _assertPropagatedAssignedType(code, typeProvider.intType, null); |
| 13541 unit, code, marker, (node) => node is SimpleIdentifier); | 13592 _assertTypeOfMarkedExpression(code, typeProvider.intType, null); |
| 13542 } catch (exception) { | 13593 } |
| 13543 // Is there a better exception to throw here? The point is that an | 13594 |
| 13544 // assertion failure here should be a failure, in both "test_*" and | 13595 void test_localVariableInference_transitive_toplevel_lexical() { |
| 13545 // "fail_*" tests. However, an assertion failure is success for the | 13596 String code = r''' |
| 13546 // purpose of "fail_*" tests, so without catching them here "fail_*" tests | 13597 int x = 3; |
| 13547 // can succeed by failing for the wrong reason. | 13598 main() { |
| 13548 throw new JavaException("Unexexpected assertion failure: $exception"); | 13599 var v = x; |
| 13549 } | 13600 return v; // marker |
| 13601 } |
| 13602 '''; |
| 13603 _assertPropagatedAssignedType(code, typeProvider.intType, null); |
| 13604 _assertTypeOfMarkedExpression(code, typeProvider.intType, null); |
| 13605 } |
| 13606 |
| 13607 void test_localVariableInference_transitive_toplevel_reversed() { |
| 13608 String code = r''' |
| 13609 main() { |
| 13610 var v = x; |
| 13611 return v; // marker |
| 13612 } |
| 13613 int x = 3; |
| 13614 '''; |
| 13615 _assertPropagatedAssignedType(code, typeProvider.intType, null); |
| 13616 _assertTypeOfMarkedExpression(code, typeProvider.intType, null); |
| 13617 } |
| 13618 |
| 13619 void fail_localVariableInference_transitive_toplevel_inferred_lexical() { |
| 13620 String code = r''' |
| 13621 final x = 3; |
| 13622 main() { |
| 13623 var v = x; |
| 13624 return v; // marker |
| 13625 } |
| 13626 '''; |
| 13627 _assertPropagatedAssignedType(code, typeProvider.intType, null); |
| 13628 _assertTypeOfMarkedExpression(code, typeProvider.intType, null); |
| 13629 } |
| 13630 |
| 13631 void fail_localVariableInference_transitive_toplevel_inferred_reversed() { |
| 13632 String code = r''' |
| 13633 main() { |
| 13634 var v = x; |
| 13635 return v; // marker |
| 13636 } |
| 13637 final x = 3; |
| 13638 '''; |
| 13639 _assertPropagatedAssignedType(code, typeProvider.intType, null); |
| 13640 _assertTypeOfMarkedExpression(code, typeProvider.intType, null); |
| 13641 } |
| 13642 |
| 13643 void test_localVariableInference_transitive_field_lexical() { |
| 13644 String code = r''' |
| 13645 class A { |
| 13646 int x = 3; |
| 13647 f() { |
| 13648 var v = x; |
| 13649 return v; // marker |
| 13650 } |
| 13651 } |
| 13652 main() { |
| 13653 } |
| 13654 '''; |
| 13655 _assertPropagatedAssignedType(code, typeProvider.intType, null); |
| 13656 _assertTypeOfMarkedExpression(code, typeProvider.intType, null); |
| 13657 } |
| 13658 |
| 13659 void test_localVariableInference_transitive_field_reversed() { |
| 13660 String code = r''' |
| 13661 class A { |
| 13662 f() { |
| 13663 var v = x; |
| 13664 return v; // marker |
| 13665 } |
| 13666 int x = 3; |
| 13667 } |
| 13668 main() { |
| 13669 } |
| 13670 '''; |
| 13671 _assertPropagatedAssignedType(code, typeProvider.intType, null); |
| 13672 _assertTypeOfMarkedExpression(code, typeProvider.intType, null); |
| 13673 } |
| 13674 |
| 13675 void fail_localVariableInference_transitive_field_inferred_lexical() { |
| 13676 String code = r''' |
| 13677 class A { |
| 13678 final x = 3; |
| 13679 f() { |
| 13680 var v = x; |
| 13681 return v; // marker |
| 13682 } |
| 13683 } |
| 13684 main() { |
| 13685 } |
| 13686 '''; |
| 13687 _assertPropagatedAssignedType(code, typeProvider.intType, null); |
| 13688 _assertTypeOfMarkedExpression(code, typeProvider.intType, null); |
| 13689 } |
| 13690 |
| 13691 void fail_localVariableInference_transitive_field_inferred_reversed() { |
| 13692 String code = r''' |
| 13693 class A { |
| 13694 f() { |
| 13695 var v = x; |
| 13696 return v; // marker |
| 13697 } |
| 13698 final x = 3; |
| 13699 } |
| 13700 main() { |
| 13701 } |
| 13702 '''; |
| 13703 _assertPropagatedAssignedType(code, typeProvider.intType, null); |
| 13704 _assertTypeOfMarkedExpression(code, typeProvider.intType, null); |
| 13705 } |
| 13706 |
| 13707 void test_localVariableInference_declaredType_disabled() { |
| 13708 String code = r''' |
| 13709 main() { |
| 13710 dynamic v = 3; |
| 13711 return v; // marker |
| 13712 }'''; |
| 13713 _assertPropagatedAssignedType( |
| 13714 code, typeProvider.dynamicType, typeProvider.intType); |
| 13715 _assertTypeOfMarkedExpression( |
| 13716 code, typeProvider.dynamicType, typeProvider.intType); |
| 13717 } |
| 13718 |
| 13719 void test_localVariableInference_bottom_disabled() { |
| 13720 String code = r''' |
| 13721 main() { |
| 13722 var v = null; |
| 13723 return v; // marker |
| 13724 }'''; |
| 13725 _assertPropagatedAssignedType(code, typeProvider.dynamicType, null); |
| 13726 _assertTypeOfMarkedExpression(code, typeProvider.dynamicType, null); |
| 13727 } |
| 13728 |
| 13729 void test_localVariableInference_noInitializer_disabled() { |
| 13730 String code = r''' |
| 13731 main() { |
| 13732 var v; |
| 13733 v = 3; |
| 13734 return v; // marker |
| 13735 }'''; |
| 13736 _assertPropagatedAssignedType( |
| 13737 code, typeProvider.dynamicType, typeProvider.intType); |
| 13738 _assertTypeOfMarkedExpression( |
| 13739 code, typeProvider.dynamicType, typeProvider.intType); |
| 13550 } | 13740 } |
| 13551 } | 13741 } |
| 13552 | 13742 |
| 13553 @reflectiveTest | 13743 @reflectiveTest |
| 13554 class TypeProviderImplTest extends EngineTestCase { | 13744 class TypeProviderImplTest extends EngineTestCase { |
| 13555 void test_creation() { | 13745 void test_creation() { |
| 13556 // | 13746 // |
| 13557 // Create a mock library element with the types expected to be in dart:core. | 13747 // Create a mock library element with the types expected to be in dart:core. |
| 13558 // We cannot use either ElementFactory or TestTypeProvider (which uses | 13748 // We cannot use either ElementFactory or TestTypeProvider (which uses |
| 13559 // ElementFactory) because we side-effect the elements in ways that would | 13749 // ElementFactory) because we side-effect the elements in ways that would |
| (...skipping 767 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14327 // check propagated type | 14517 // check propagated type |
| 14328 FunctionType propagatedType = node.propagatedType as FunctionType; | 14518 FunctionType propagatedType = node.propagatedType as FunctionType; |
| 14329 expect(propagatedType.returnType, test.typeProvider.stringType); | 14519 expect(propagatedType.returnType, test.typeProvider.stringType); |
| 14330 } on AnalysisException catch (e, stackTrace) { | 14520 } on AnalysisException catch (e, stackTrace) { |
| 14331 thrownException[0] = new CaughtException(e, stackTrace); | 14521 thrownException[0] = new CaughtException(e, stackTrace); |
| 14332 } | 14522 } |
| 14333 } | 14523 } |
| 14334 return null; | 14524 return null; |
| 14335 } | 14525 } |
| 14336 } | 14526 } |
| OLD | NEW |