| 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 analyzer.test.generated.resolver_test; | 5 library analyzer.test.generated.resolver_test; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:collection'; | 8 import 'dart:collection'; |
| 9 | 9 |
| 10 import 'package:analyzer/dart/ast/ast.dart'; | 10 import 'package:analyzer/dart/ast/ast.dart'; |
| (...skipping 1022 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1033 d = false; | 1033 d = false; |
| 1034 } else { | 1034 } else { |
| 1035 x = ''; | 1035 x = ''; |
| 1036 c = true; | 1036 c = true; |
| 1037 continue; | 1037 continue; |
| 1038 } | 1038 } |
| 1039 x; // marker | 1039 x; // marker |
| 1040 } | 1040 } |
| 1041 }'''; | 1041 }'''; |
| 1042 CompilationUnit unit = await resolveSource(code); | 1042 CompilationUnit unit = await resolveSource(code); |
| 1043 DartType t = | 1043 DartType t = findMarkedIdentifier(code, unit, "; // marker").propagatedType; |
| 1044 findMarkedIdentifier(code, unit, "; // marker").propagatedType; | |
| 1045 expect(typeProvider.intType.isSubtypeOf(t), isTrue); | 1044 expect(typeProvider.intType.isSubtypeOf(t), isTrue); |
| 1046 expect(typeProvider.stringType.isSubtypeOf(t), isTrue); | 1045 expect(typeProvider.stringType.isSubtypeOf(t), isTrue); |
| 1047 } | 1046 } |
| 1048 | 1047 |
| 1049 fail_mergePropagatedTypesAtJoinPoint_8() async { | 1048 fail_mergePropagatedTypesAtJoinPoint_8() async { |
| 1050 // https://code.google.com/p/dart/issues/detail?id=19929 | 1049 // https://code.google.com/p/dart/issues/detail?id=19929 |
| 1051 // | 1050 // |
| 1052 // In nested loops [breaks]s are unsafe for the purposes of | 1051 // In nested loops [breaks]s are unsafe for the purposes of |
| 1053 // [isAbruptTerminationStatement]. | 1052 // [isAbruptTerminationStatement]. |
| 1054 // | 1053 // |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1067 } else { | 1066 } else { |
| 1068 x = ''; | 1067 x = ''; |
| 1069 c = true; | 1068 c = true; |
| 1070 break; | 1069 break; |
| 1071 } | 1070 } |
| 1072 x; // marker | 1071 x; // marker |
| 1073 } | 1072 } |
| 1074 } | 1073 } |
| 1075 }'''; | 1074 }'''; |
| 1076 CompilationUnit unit = await resolveSource(code); | 1075 CompilationUnit unit = await resolveSource(code); |
| 1077 DartType t = | 1076 DartType t = findMarkedIdentifier(code, unit, "; // marker").propagatedType; |
| 1078 findMarkedIdentifier(code, unit, "; // marker").propagatedType; | |
| 1079 expect(typeProvider.intType.isSubtypeOf(t), isTrue); | 1077 expect(typeProvider.intType.isSubtypeOf(t), isTrue); |
| 1080 expect(typeProvider.stringType.isSubtypeOf(t), isTrue); | 1078 expect(typeProvider.stringType.isSubtypeOf(t), isTrue); |
| 1081 } | 1079 } |
| 1082 | 1080 |
| 1083 fail_propagatedReturnType_functionExpression() async { | 1081 fail_propagatedReturnType_functionExpression() async { |
| 1084 // TODO(scheglov) disabled because we don't resolve function expression | 1082 // TODO(scheglov) disabled because we don't resolve function expression |
| 1085 String code = r''' | 1083 String code = r''' |
| 1086 main() { | 1084 main() { |
| 1087 var v = (() {return 42;})(); | 1085 var v = (() {return 42;})(); |
| 1088 }'''; | 1086 }'''; |
| (...skipping 987 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2076 v = ''; | 2074 v = ''; |
| 2077 } | 2075 } |
| 2078 return v; | 2076 return v; |
| 2079 }'''; | 2077 }'''; |
| 2080 CompilationUnit unit = await resolveSource(code); | 2078 CompilationUnit unit = await resolveSource(code); |
| 2081 { | 2079 { |
| 2082 SimpleIdentifier identifier = findMarkedIdentifier(code, unit, "v;"); | 2080 SimpleIdentifier identifier = findMarkedIdentifier(code, unit, "v;"); |
| 2083 expect(identifier.propagatedType, null); | 2081 expect(identifier.propagatedType, null); |
| 2084 } | 2082 } |
| 2085 { | 2083 { |
| 2086 SimpleIdentifier identifier = | 2084 SimpleIdentifier identifier = findMarkedIdentifier(code, unit, "v = '';"); |
| 2087 findMarkedIdentifier(code, unit, "v = '';"); | |
| 2088 expect(identifier.propagatedType, typeProvider.stringType); | 2085 expect(identifier.propagatedType, typeProvider.stringType); |
| 2089 } | 2086 } |
| 2090 } | 2087 } |
| 2091 | 2088 |
| 2092 test_mergePropagatedTypes_afterIfThen_same() async { | 2089 test_mergePropagatedTypes_afterIfThen_same() async { |
| 2093 var code = r''' | 2090 var code = r''' |
| 2094 main() { | 2091 main() { |
| 2095 var v = 1; | 2092 var v = 1; |
| 2096 if (v != null) { | 2093 if (v != null) { |
| 2097 v = 2; | 2094 v = 2; |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2418 // We cannot use either ElementFactory or TestTypeProvider (which uses | 2415 // We cannot use either ElementFactory or TestTypeProvider (which uses |
| 2419 // ElementFactory) because we side-effect the elements in ways that would | 2416 // ElementFactory) because we side-effect the elements in ways that would |
| 2420 // break other tests. | 2417 // break other tests. |
| 2421 // | 2418 // |
| 2422 InterfaceType objectType = _classElement("Object", null).type; | 2419 InterfaceType objectType = _classElement("Object", null).type; |
| 2423 InterfaceType boolType = _classElement("bool", objectType).type; | 2420 InterfaceType boolType = _classElement("bool", objectType).type; |
| 2424 InterfaceType numType = _classElement("num", objectType).type; | 2421 InterfaceType numType = _classElement("num", objectType).type; |
| 2425 InterfaceType doubleType = _classElement("double", numType).type; | 2422 InterfaceType doubleType = _classElement("double", numType).type; |
| 2426 InterfaceType functionType = _classElement("Function", objectType).type; | 2423 InterfaceType functionType = _classElement("Function", objectType).type; |
| 2427 InterfaceType futureType = _classElement("Future", objectType, ["T"]).type; | 2424 InterfaceType futureType = _classElement("Future", objectType, ["T"]).type; |
| 2428 InterfaceType futureOrType = _classElement("FutureOr", objectType, ["T"]).ty
pe; | 2425 InterfaceType futureOrType = |
| 2426 _classElement("FutureOr", objectType, ["T"]).type; |
| 2429 InterfaceType intType = _classElement("int", numType).type; | 2427 InterfaceType intType = _classElement("int", numType).type; |
| 2430 InterfaceType iterableType = | 2428 InterfaceType iterableType = |
| 2431 _classElement("Iterable", objectType, ["T"]).type; | 2429 _classElement("Iterable", objectType, ["T"]).type; |
| 2432 InterfaceType listType = _classElement("List", objectType, ["E"]).type; | 2430 InterfaceType listType = _classElement("List", objectType, ["E"]).type; |
| 2433 InterfaceType mapType = _classElement("Map", objectType, ["K", "V"]).type; | 2431 InterfaceType mapType = _classElement("Map", objectType, ["K", "V"]).type; |
| 2434 InterfaceType stackTraceType = _classElement("StackTrace", objectType).type; | 2432 InterfaceType stackTraceType = _classElement("StackTrace", objectType).type; |
| 2435 InterfaceType streamType = _classElement("Stream", objectType, ["T"]).type; | 2433 InterfaceType streamType = _classElement("Stream", objectType, ["T"]).type; |
| 2436 InterfaceType stringType = _classElement("String", objectType).type; | 2434 InterfaceType stringType = _classElement("String", objectType).type; |
| 2437 InterfaceType symbolType = _classElement("Symbol", objectType).type; | 2435 InterfaceType symbolType = _classElement("Symbol", objectType).type; |
| 2438 InterfaceType typeType = _classElement("Type", objectType).type; | 2436 InterfaceType typeType = _classElement("Type", objectType).type; |
| 2439 CompilationUnitElementImpl coreUnit = | 2437 CompilationUnitElementImpl coreUnit = |
| 2440 new CompilationUnitElementImpl("core.dart"); | 2438 new CompilationUnitElementImpl("core.dart"); |
| 2441 coreUnit.types = <ClassElement>[ | 2439 coreUnit.types = <ClassElement>[ |
| 2442 boolType.element, | 2440 boolType.element, |
| 2443 doubleType.element, | 2441 doubleType.element, |
| 2444 functionType.element, | 2442 functionType.element, |
| 2445 intType.element, | 2443 intType.element, |
| 2446 iterableType.element, | 2444 iterableType.element, |
| 2447 listType.element, | 2445 listType.element, |
| 2448 mapType.element, | 2446 mapType.element, |
| 2449 objectType.element, | 2447 objectType.element, |
| 2450 stackTraceType.element, | 2448 stackTraceType.element, |
| 2451 stringType.element, | 2449 stringType.element, |
| 2452 symbolType.element, | 2450 symbolType.element, |
| 2453 typeType.element | 2451 typeType.element |
| 2454 ]; | 2452 ]; |
| 2455 CompilationUnitElementImpl asyncUnit = | 2453 CompilationUnitElementImpl asyncUnit = |
| 2456 new CompilationUnitElementImpl("async.dart"); | 2454 new CompilationUnitElementImpl("async.dart"); |
| 2457 asyncUnit.types = <ClassElement>[futureType.element, futureOrType.element, s
treamType.element]; | 2455 asyncUnit.types = <ClassElement>[ |
| 2456 futureType.element, |
| 2457 futureOrType.element, |
| 2458 streamType.element |
| 2459 ]; |
| 2458 AnalysisContext context = AnalysisEngine.instance.createAnalysisContext(); | 2460 AnalysisContext context = AnalysisEngine.instance.createAnalysisContext(); |
| 2459 LibraryElementImpl coreLibrary = new LibraryElementImpl.forNode( | 2461 LibraryElementImpl coreLibrary = new LibraryElementImpl.forNode( |
| 2460 context, AstTestFactory.libraryIdentifier2(["dart.core"])); | 2462 context, AstTestFactory.libraryIdentifier2(["dart.core"])); |
| 2461 coreLibrary.definingCompilationUnit = coreUnit; | 2463 coreLibrary.definingCompilationUnit = coreUnit; |
| 2462 LibraryElementImpl asyncLibrary = new LibraryElementImpl.forNode( | 2464 LibraryElementImpl asyncLibrary = new LibraryElementImpl.forNode( |
| 2463 context, AstTestFactory.libraryIdentifier2(["dart.async"])); | 2465 context, AstTestFactory.libraryIdentifier2(["dart.async"])); |
| 2464 asyncLibrary.definingCompilationUnit = asyncUnit; | 2466 asyncLibrary.definingCompilationUnit = asyncUnit; |
| 2465 // | 2467 // |
| 2466 // Create a type provider and ensure that it can return the expected types. | 2468 // Create a type provider and ensure that it can return the expected types. |
| 2467 // | 2469 // |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2505 typeParameter.type = typeArguments[i]; | 2507 typeParameter.type = typeArguments[i]; |
| 2506 } | 2508 } |
| 2507 element.typeParameters = typeParameters; | 2509 element.typeParameters = typeParameters; |
| 2508 } | 2510 } |
| 2509 } | 2511 } |
| 2510 return element; | 2512 return element; |
| 2511 } | 2513 } |
| 2512 } | 2514 } |
| 2513 | 2515 |
| 2514 @reflectiveTest | 2516 @reflectiveTest |
| 2515 class TypeResolverVisitorTest { | 2517 class TypeResolverVisitorTest extends ParserTestCase { |
| 2516 /** | 2518 /** |
| 2517 * The error listener to which errors will be reported. | 2519 * The error listener to which errors will be reported. |
| 2518 */ | 2520 */ |
| 2519 GatheringErrorListener _listener; | 2521 GatheringErrorListener _listener; |
| 2520 | 2522 |
| 2521 /** | 2523 /** |
| 2522 * The type provider used to access the types. | 2524 * The type provider used to access the types. |
| 2523 */ | 2525 */ |
| 2524 TestTypeProvider _typeProvider; | 2526 TestTypeProvider _typeProvider; |
| 2525 | 2527 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2566 element.definingCompilationUnit = | 2568 element.definingCompilationUnit = |
| 2567 new CompilationUnitElementImpl("lib.dart"); | 2569 new CompilationUnitElementImpl("lib.dart"); |
| 2568 _typeProvider = new TestTypeProvider(); | 2570 _typeProvider = new TestTypeProvider(); |
| 2569 libraryScope = new LibraryScope(element); | 2571 libraryScope = new LibraryScope(element); |
| 2570 _visitor = new TypeResolverVisitor( | 2572 _visitor = new TypeResolverVisitor( |
| 2571 element, librarySource, _typeProvider, _listener, | 2573 element, librarySource, _typeProvider, _listener, |
| 2572 nameScope: libraryScope); | 2574 nameScope: libraryScope); |
| 2573 } | 2575 } |
| 2574 | 2576 |
| 2575 test_modeApi() async { | 2577 test_modeApi() async { |
| 2576 CompilationUnit unit = ParserTestCase.parseCompilationUnit(r''' | 2578 CompilationUnit unit = parseCompilationUnit(r''' |
| 2577 class C extends A with A implements A { | 2579 class C extends A with A implements A { |
| 2578 A f = new A(); | 2580 A f = new A(); |
| 2579 A m() { | 2581 A m() { |
| 2580 A v1; | 2582 A v1; |
| 2581 } | 2583 } |
| 2582 } | 2584 } |
| 2583 A f([A p = const A()]) { | 2585 A f([A p = const A()]) { |
| 2584 A v2; | 2586 A v2; |
| 2585 } | 2587 } |
| 2586 A V = new A(); | 2588 A V = new A(); |
| (...skipping 973 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3560 node.accept(_visitor); | 3562 node.accept(_visitor); |
| 3561 } | 3563 } |
| 3562 | 3564 |
| 3563 /** | 3565 /** |
| 3564 * Parse the given [code], build elements and resolve in the | 3566 * Parse the given [code], build elements and resolve in the |
| 3565 * [TypeResolverMode.local] mode. The [code] is allowed to use only the type | 3567 * [TypeResolverMode.local] mode. The [code] is allowed to use only the type |
| 3566 * named `A`. | 3568 * named `A`. |
| 3567 */ | 3569 */ |
| 3568 void _resolveTypeModeLocal( | 3570 void _resolveTypeModeLocal( |
| 3569 String code, AstNode getNodeToResolve(CompilationUnit unit)) { | 3571 String code, AstNode getNodeToResolve(CompilationUnit unit)) { |
| 3570 CompilationUnit unit = ParserTestCase.parseCompilationUnit2(code); | 3572 CompilationUnit unit = parseCompilationUnit2(code); |
| 3571 var unitElement = new CompilationUnitElementImpl('/test.dart'); | 3573 var unitElement = new CompilationUnitElementImpl('/test.dart'); |
| 3572 | 3574 |
| 3573 // Build API elements. | 3575 // Build API elements. |
| 3574 { | 3576 { |
| 3575 var holder = new ElementHolder(); | 3577 var holder = new ElementHolder(); |
| 3576 unit.accept(new ElementBuilder(holder, unitElement)); | 3578 unit.accept(new ElementBuilder(holder, unitElement)); |
| 3577 } | 3579 } |
| 3578 | 3580 |
| 3579 // Prepare for resolution. | 3581 // Prepare for resolution. |
| 3580 LibraryScope libraryScope; | 3582 LibraryScope libraryScope; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3616 */ | 3618 */ |
| 3617 class _StaleElement extends ElementImpl { | 3619 class _StaleElement extends ElementImpl { |
| 3618 _StaleElement() : super("_StaleElement", -1); | 3620 _StaleElement() : super("_StaleElement", -1); |
| 3619 | 3621 |
| 3620 @override | 3622 @override |
| 3621 get kind => throw "_StaleElement's kind shouldn't be accessed"; | 3623 get kind => throw "_StaleElement's kind shouldn't be accessed"; |
| 3622 | 3624 |
| 3623 @override | 3625 @override |
| 3624 /*=T*/ accept/*<T>*/(_) => throw "_StaleElement shouldn't be visited"; | 3626 /*=T*/ accept/*<T>*/(_) => throw "_StaleElement shouldn't be visited"; |
| 3625 } | 3627 } |
| OLD | NEW |