| 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/generated/ast.dart'; | 9 import 'package:analyzer/src/generated/ast.dart'; |
| 10 import 'package:analyzer/src/generated/element.dart'; | 10 import 'package:analyzer/src/generated/element.dart'; |
| (...skipping 6741 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6752 } | 6752 } |
| 6753 class B extends A { | 6753 class B extends A { |
| 6754 @override | 6754 @override |
| 6755 set m(int x) {} | 6755 set m(int x) {} |
| 6756 }'''); | 6756 }'''); |
| 6757 resolve(source); | 6757 resolve(source); |
| 6758 assertNoErrors(source); | 6758 assertNoErrors(source); |
| 6759 verify([source]); | 6759 verify([source]); |
| 6760 } | 6760 } |
| 6761 | 6761 |
| 6762 void test_propagatedFieldType() { | 6762 void fail_propagatedFieldType() { |
| 6763 // From dartbug.com/20019 | 6763 // From dartbug.com/20019 |
| 6764 Source source = addSource(r''' | 6764 Source source = addSource(r''' |
| 6765 class A { } | 6765 class A { } |
| 6766 class X<T> { | 6766 class X<T> { |
| 6767 final x = new List<T>(); | 6767 final x = new List<T>(); |
| 6768 } | 6768 } |
| 6769 class Z { | 6769 class Z { |
| 6770 final X<A> y = new X<A>(); | 6770 final X<A> y = new X<A>(); |
| 6771 foo() { | 6771 foo() { |
| 6772 y.x.add(new A()); | 6772 y.x.add(new A()); |
| (...skipping 5182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11955 verify([source]); | 11955 verify([source]); |
| 11956 CompilationUnit unit = resolveCompilationUnit(source, library); | 11956 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 11957 SimpleIdentifier identifier = EngineTestCase.findNode( | 11957 SimpleIdentifier identifier = EngineTestCase.findNode( |
| 11958 unit, | 11958 unit, |
| 11959 code, | 11959 code, |
| 11960 "context", | 11960 "context", |
| 11961 (node) => node is SimpleIdentifier); | 11961 (node) => node is SimpleIdentifier); |
| 11962 expect(identifier.propagatedType.name, "CanvasRenderingContext2D"); | 11962 expect(identifier.propagatedType.name, "CanvasRenderingContext2D"); |
| 11963 } | 11963 } |
| 11964 | 11964 |
| 11965 void test_finalPropertyInducingVariable_classMember_instance() { | 11965 void fail_finalPropertyInducingVariable_classMember_instance() { |
| 11966 addNamedSource("/lib.dart", r''' | 11966 addNamedSource("/lib.dart", r''' |
| 11967 class A { | 11967 class A { |
| 11968 final v = 0; | 11968 final v = 0; |
| 11969 }'''); | 11969 }'''); |
| 11970 String code = r''' | 11970 String code = r''' |
| 11971 import 'lib.dart'; | 11971 import 'lib.dart'; |
| 11972 f(A a) { | 11972 f(A a) { |
| 11973 return a.v; // marker | 11973 return a.v; // marker |
| 11974 }'''; | 11974 }'''; |
| 11975 _assertTypeOfMarkedExpression( | 11975 _assertTypeOfMarkedExpression( |
| 11976 code, | 11976 code, |
| 11977 typeProvider.dynamicType, | 11977 typeProvider.dynamicType, |
| 11978 typeProvider.intType); | 11978 typeProvider.intType); |
| 11979 } | 11979 } |
| 11980 | 11980 |
| 11981 void test_finalPropertyInducingVariable_classMember_instance_inherited() { | 11981 void fail_finalPropertyInducingVariable_classMember_instance_inherited() { |
| 11982 addNamedSource("/lib.dart", r''' | 11982 addNamedSource("/lib.dart", r''' |
| 11983 class A { | 11983 class A { |
| 11984 final v = 0; | 11984 final v = 0; |
| 11985 }'''); | 11985 }'''); |
| 11986 String code = r''' | 11986 String code = r''' |
| 11987 import 'lib.dart'; | 11987 import 'lib.dart'; |
| 11988 class B extends A { | 11988 class B extends A { |
| 11989 m() { | 11989 m() { |
| 11990 return v; // marker | 11990 return v; // marker |
| 11991 } | 11991 } |
| 11992 }'''; | 11992 }'''; |
| 11993 _assertTypeOfMarkedExpression( | 11993 _assertTypeOfMarkedExpression( |
| 11994 code, | 11994 code, |
| 11995 typeProvider.dynamicType, | 11995 typeProvider.dynamicType, |
| 11996 typeProvider.intType); | 11996 typeProvider.intType); |
| 11997 } | 11997 } |
| 11998 | 11998 |
| 11999 void | 11999 void |
| 12000 test_finalPropertyInducingVariable_classMember_instance_propagatedTarget()
{ | 12000 fail_finalPropertyInducingVariable_classMember_instance_propagatedTarget()
{ |
| 12001 addNamedSource("/lib.dart", r''' | 12001 addNamedSource("/lib.dart", r''' |
| 12002 class A { | 12002 class A { |
| 12003 final v = 0; | 12003 final v = 0; |
| 12004 }'''); | 12004 }'''); |
| 12005 String code = r''' | 12005 String code = r''' |
| 12006 import 'lib.dart'; | 12006 import 'lib.dart'; |
| 12007 f(p) { | 12007 f(p) { |
| 12008 if (p is A) { | 12008 if (p is A) { |
| 12009 return p.v; // marker | 12009 return p.v; // marker |
| 12010 } | 12010 } |
| 12011 }'''; | 12011 }'''; |
| 12012 _assertTypeOfMarkedExpression( | 12012 _assertTypeOfMarkedExpression( |
| 12013 code, | 12013 code, |
| 12014 typeProvider.dynamicType, | 12014 typeProvider.dynamicType, |
| 12015 typeProvider.intType); | 12015 typeProvider.intType); |
| 12016 } | 12016 } |
| 12017 | 12017 |
| 12018 void test_finalPropertyInducingVariable_classMember_static() { | 12018 void fail_finalPropertyInducingVariable_classMember_static() { |
| 12019 addNamedSource("/lib.dart", r''' | 12019 addNamedSource("/lib.dart", r''' |
| 12020 class A { | 12020 class A { |
| 12021 static final V = 0; | 12021 static final V = 0; |
| 12022 }'''); | 12022 }'''); |
| 12023 String code = r''' | 12023 String code = r''' |
| 12024 import 'lib.dart'; | 12024 import 'lib.dart'; |
| 12025 f() { | 12025 f() { |
| 12026 return A.V; // marker | 12026 return A.V; // marker |
| 12027 }'''; | 12027 }'''; |
| 12028 _assertTypeOfMarkedExpression( | 12028 _assertTypeOfMarkedExpression( |
| 12029 code, | 12029 code, |
| 12030 typeProvider.dynamicType, | 12030 typeProvider.dynamicType, |
| 12031 typeProvider.intType); | 12031 typeProvider.intType); |
| 12032 } | 12032 } |
| 12033 | 12033 |
| 12034 void test_finalPropertyInducingVariable_topLevelVaraible_prefixed() { | 12034 void fail_finalPropertyInducingVariable_topLevelVaraible_prefixed() { |
| 12035 addNamedSource("/lib.dart", "final V = 0;"); | 12035 addNamedSource("/lib.dart", "final V = 0;"); |
| 12036 String code = r''' | 12036 String code = r''' |
| 12037 import 'lib.dart' as p; | 12037 import 'lib.dart' as p; |
| 12038 f() { | 12038 f() { |
| 12039 var v2 = p.V; // marker prefixed | 12039 var v2 = p.V; // marker prefixed |
| 12040 }'''; | 12040 }'''; |
| 12041 _assertTypeOfMarkedExpression( | 12041 _assertTypeOfMarkedExpression( |
| 12042 code, | 12042 code, |
| 12043 typeProvider.dynamicType, | 12043 typeProvider.dynamicType, |
| 12044 typeProvider.intType); | 12044 typeProvider.intType); |
| 12045 } | 12045 } |
| 12046 | 12046 |
| 12047 void test_finalPropertyInducingVariable_topLevelVaraible_simple() { | 12047 void fail_finalPropertyInducingVariable_topLevelVaraible_simple() { |
| 12048 addNamedSource("/lib.dart", "final V = 0;"); | 12048 addNamedSource("/lib.dart", "final V = 0;"); |
| 12049 String code = r''' | 12049 String code = r''' |
| 12050 import 'lib.dart'; | 12050 import 'lib.dart'; |
| 12051 f() { | 12051 f() { |
| 12052 return V; // marker simple | 12052 return V; // marker simple |
| 12053 }'''; | 12053 }'''; |
| 12054 _assertTypeOfMarkedExpression( | 12054 _assertTypeOfMarkedExpression( |
| 12055 code, | 12055 code, |
| 12056 typeProvider.dynamicType, | 12056 typeProvider.dynamicType, |
| 12057 typeProvider.intType); | 12057 typeProvider.intType); |
| (...skipping 1771 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13829 // check propagated type | 13829 // check propagated type |
| 13830 FunctionType propagatedType = node.propagatedType as FunctionType; | 13830 FunctionType propagatedType = node.propagatedType as FunctionType; |
| 13831 expect(propagatedType.returnType, test.typeProvider.stringType); | 13831 expect(propagatedType.returnType, test.typeProvider.stringType); |
| 13832 } on AnalysisException catch (e, stackTrace) { | 13832 } on AnalysisException catch (e, stackTrace) { |
| 13833 thrownException[0] = new CaughtException(e, stackTrace); | 13833 thrownException[0] = new CaughtException(e, stackTrace); |
| 13834 } | 13834 } |
| 13835 } | 13835 } |
| 13836 return null; | 13836 return null; |
| 13837 } | 13837 } |
| 13838 } | 13838 } |
| OLD | NEW |