| 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 12685 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12696 } | 12696 } |
| 12697 | 12697 |
| 12698 void test_getType_noScope() { | 12698 void test_getType_noScope() { |
| 12699 TypeOverrideManager manager = new TypeOverrideManager(); | 12699 TypeOverrideManager manager = new TypeOverrideManager(); |
| 12700 expect(manager.getType(ElementFactory.localVariableElement2("v")), isNull); | 12700 expect(manager.getType(ElementFactory.localVariableElement2("v")), isNull); |
| 12701 } | 12701 } |
| 12702 } | 12702 } |
| 12703 | 12703 |
| 12704 @reflectiveTest | 12704 @reflectiveTest |
| 12705 class TypePropagationTest extends ResolverTestCase { | 12705 class TypePropagationTest extends ResolverTestCase { |
| 12706 void fail_finalPropertyInducingVariable_classMember_instance() { | |
| 12707 addNamedSource( | |
| 12708 "/lib.dart", | |
| 12709 r''' | |
| 12710 class A { | |
| 12711 final v = 0; | |
| 12712 }'''); | |
| 12713 String code = r''' | |
| 12714 import 'lib.dart'; | |
| 12715 f(A a) { | |
| 12716 return a.v; // marker | |
| 12717 }'''; | |
| 12718 _assertTypeOfMarkedExpression( | |
| 12719 code, typeProvider.dynamicType, typeProvider.intType); | |
| 12720 } | |
| 12721 | |
| 12722 void fail_finalPropertyInducingVariable_classMember_instance_inherited() { | |
| 12723 addNamedSource( | |
| 12724 "/lib.dart", | |
| 12725 r''' | |
| 12726 class A { | |
| 12727 final v = 0; | |
| 12728 }'''); | |
| 12729 String code = r''' | |
| 12730 import 'lib.dart'; | |
| 12731 class B extends A { | |
| 12732 m() { | |
| 12733 return v; // marker | |
| 12734 } | |
| 12735 }'''; | |
| 12736 _assertTypeOfMarkedExpression( | |
| 12737 code, typeProvider.dynamicType, typeProvider.intType); | |
| 12738 } | |
| 12739 | |
| 12740 void fail_finalPropertyInducingVariable_classMember_instance_propagatedTarget(
) { | |
| 12741 addNamedSource( | |
| 12742 "/lib.dart", | |
| 12743 r''' | |
| 12744 class A { | |
| 12745 final v = 0; | |
| 12746 }'''); | |
| 12747 String code = r''' | |
| 12748 import 'lib.dart'; | |
| 12749 f(p) { | |
| 12750 if (p is A) { | |
| 12751 return p.v; // marker | |
| 12752 } | |
| 12753 }'''; | |
| 12754 _assertTypeOfMarkedExpression( | |
| 12755 code, typeProvider.dynamicType, typeProvider.intType); | |
| 12756 } | |
| 12757 | |
| 12758 void fail_finalPropertyInducingVariable_classMember_instance_unprefixed() { | |
| 12759 String code = r''' | |
| 12760 class A { | |
| 12761 final v = 0; | |
| 12762 m() { | |
| 12763 v; // marker | |
| 12764 } | |
| 12765 }'''; | |
| 12766 _assertTypeOfMarkedExpression( | |
| 12767 code, typeProvider.dynamicType, typeProvider.intType); | |
| 12768 } | |
| 12769 | |
| 12770 void fail_finalPropertyInducingVariable_classMember_static() { | 12706 void fail_finalPropertyInducingVariable_classMember_static() { |
| 12771 addNamedSource( | 12707 addNamedSource( |
| 12772 "/lib.dart", | 12708 "/lib.dart", |
| 12773 r''' | 12709 r''' |
| 12774 class A { | 12710 class A { |
| 12775 static final V = 0; | 12711 static final V = 0; |
| 12776 }'''); | 12712 }'''); |
| 12777 String code = r''' | 12713 String code = r''' |
| 12778 import 'lib.dart'; | 12714 import 'lib.dart'; |
| 12779 f() { | 12715 f() { |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13082 Source source = addSource(code); | 13018 Source source = addSource(code); |
| 13083 LibraryElement library = resolve2(source); | 13019 LibraryElement library = resolve2(source); |
| 13084 assertNoErrors(source); | 13020 assertNoErrors(source); |
| 13085 verify([source]); | 13021 verify([source]); |
| 13086 CompilationUnit unit = resolveCompilationUnit(source, library); | 13022 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 13087 SimpleIdentifier identifier = EngineTestCase.findNode( | 13023 SimpleIdentifier identifier = EngineTestCase.findNode( |
| 13088 unit, code, "context", (node) => node is SimpleIdentifier); | 13024 unit, code, "context", (node) => node is SimpleIdentifier); |
| 13089 expect(identifier.propagatedType.name, "CanvasRenderingContext2D"); | 13025 expect(identifier.propagatedType.name, "CanvasRenderingContext2D"); |
| 13090 } | 13026 } |
| 13091 | 13027 |
| 13028 void test_finalPropertyInducingVariable_classMember_instance() { |
| 13029 addNamedSource( |
| 13030 "/lib.dart", |
| 13031 r''' |
| 13032 class A { |
| 13033 final v = 0; |
| 13034 }'''); |
| 13035 String code = r''' |
| 13036 import 'lib.dart'; |
| 13037 f(A a) { |
| 13038 return a.v; // marker |
| 13039 }'''; |
| 13040 _assertTypeOfMarkedExpression( |
| 13041 code, typeProvider.dynamicType, typeProvider.intType); |
| 13042 } |
| 13043 |
| 13044 void test_finalPropertyInducingVariable_classMember_instance_inherited() { |
| 13045 addNamedSource( |
| 13046 "/lib.dart", |
| 13047 r''' |
| 13048 class A { |
| 13049 final v = 0; |
| 13050 }'''); |
| 13051 String code = r''' |
| 13052 import 'lib.dart'; |
| 13053 class B extends A { |
| 13054 m() { |
| 13055 return v; // marker |
| 13056 } |
| 13057 }'''; |
| 13058 _assertTypeOfMarkedExpression( |
| 13059 code, typeProvider.dynamicType, typeProvider.intType); |
| 13060 } |
| 13061 |
| 13062 void test_finalPropertyInducingVariable_classMember_instance_propagatedTarget(
) { |
| 13063 addNamedSource( |
| 13064 "/lib.dart", |
| 13065 r''' |
| 13066 class A { |
| 13067 final v = 0; |
| 13068 }'''); |
| 13069 String code = r''' |
| 13070 import 'lib.dart'; |
| 13071 f(p) { |
| 13072 if (p is A) { |
| 13073 return p.v; // marker |
| 13074 } |
| 13075 }'''; |
| 13076 _assertTypeOfMarkedExpression( |
| 13077 code, typeProvider.dynamicType, typeProvider.intType); |
| 13078 } |
| 13079 |
| 13080 void test_finalPropertyInducingVariable_classMember_instance_unprefixed() { |
| 13081 String code = r''' |
| 13082 class A { |
| 13083 final v = 0; |
| 13084 m() { |
| 13085 v; // marker |
| 13086 } |
| 13087 }'''; |
| 13088 _assertTypeOfMarkedExpression( |
| 13089 code, typeProvider.dynamicType, typeProvider.intType); |
| 13090 } |
| 13091 |
| 13092 void test_forEach() { | 13092 void test_forEach() { |
| 13093 String code = r''' | 13093 String code = r''' |
| 13094 main() { | 13094 main() { |
| 13095 var list = <String> []; | 13095 var list = <String> []; |
| 13096 for (var e in list) { | 13096 for (var e in list) { |
| 13097 e; | 13097 e; |
| 13098 } | 13098 } |
| 13099 }'''; | 13099 }'''; |
| 13100 Source source = addSource(code); | 13100 Source source = addSource(code); |
| 13101 LibraryElement library = resolve2(source); | 13101 LibraryElement library = resolve2(source); |
| (...skipping 1960 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15062 | 15062 |
| 15063 void _resolveTestUnit(String code) { | 15063 void _resolveTestUnit(String code) { |
| 15064 testCode = code; | 15064 testCode = code; |
| 15065 testSource = addSource(testCode); | 15065 testSource = addSource(testCode); |
| 15066 LibraryElement library = resolve2(testSource); | 15066 LibraryElement library = resolve2(testSource); |
| 15067 assertNoErrors(testSource); | 15067 assertNoErrors(testSource); |
| 15068 verify([testSource]); | 15068 verify([testSource]); |
| 15069 testUnit = resolveCompilationUnit(testSource, library); | 15069 testUnit = resolveCompilationUnit(testSource, library); |
| 15070 } | 15070 } |
| 15071 } | 15071 } |
| OLD | NEW |