| 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:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'package:analyzer/dart/element/element.dart'; | 9 import 'package:analyzer/dart/element/element.dart'; |
| 10 import 'package:analyzer/dart/element/type.dart'; | 10 import 'package:analyzer/dart/element/type.dart'; |
| (...skipping 13016 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13027 check("f2", _isListOf(_isInt)); | 13027 check("f2", _isListOf(_isInt)); |
| 13028 check("f3", _isListOf(_isListOf(_isInt))); | 13028 check("f3", _isListOf(_isListOf(_isInt))); |
| 13029 } | 13029 } |
| 13030 } | 13030 } |
| 13031 | 13031 |
| 13032 /** | 13032 /** |
| 13033 * Strong mode static analyzer end to end tests | 13033 * Strong mode static analyzer end to end tests |
| 13034 */ | 13034 */ |
| 13035 @reflectiveTest | 13035 @reflectiveTest |
| 13036 class StrongModeStaticTypeAnalyzer2Test extends _StaticTypeAnalyzer2TestShared { | 13036 class StrongModeStaticTypeAnalyzer2Test extends _StaticTypeAnalyzer2TestShared { |
| 13037 void test_genericMethod_functionExpressionInvocation_explicit() { | |
| 13038 _resolveTestUnit(r''' | |
| 13039 class C<E> { | |
| 13040 /*=T*/ f/*<T>*/(/*=T*/ e) => null; | |
| 13041 static /*=T*/ g/*<T>*/(/*=T*/ e) => null; | |
| 13042 static final h = g; | |
| 13043 } | |
| 13044 | |
| 13045 /*=T*/ topF/*<T>*/(/*=T*/ e) => null; | |
| 13046 var topG = topF; | |
| 13047 void test/*<S>*/(/*=T*/ pf/*<T>*/(/*=T*/ e)) { | |
| 13048 var c = new C<int>(); | |
| 13049 /*=T*/ lf/*<T>*/(/*=T*/ e) => null; | |
| 13050 | |
| 13051 var lambdaCall = (/*<E>*/(/*=E*/ e) => e)/*<int>*/(3); | |
| 13052 var methodCall = (c.f)/*<int>*/(3); | |
| 13053 var staticCall = (C.g)/*<int>*/(3); | |
| 13054 var staticFieldCall = (C.h)/*<int>*/(3); | |
| 13055 var topFunCall = (topF)/*<int>*/(3); | |
| 13056 var topFieldCall = (topG)/*<int>*/(3); | |
| 13057 var localCall = (lf)/*<int>*/(3); | |
| 13058 var paramCall = (pf)/*<int>*/(3); | |
| 13059 } | |
| 13060 '''); | |
| 13061 expect(_findIdentifier('methodCall').staticType.toString(), "int"); | |
| 13062 expect(_findIdentifier('staticCall').staticType.toString(), "int"); | |
| 13063 expect(_findIdentifier('staticFieldCall').staticType.toString(), "int"); | |
| 13064 expect(_findIdentifier('topFunCall').staticType.toString(), "int"); | |
| 13065 expect(_findIdentifier('topFieldCall').staticType.toString(), "int"); | |
| 13066 expect(_findIdentifier('localCall').staticType.toString(), "int"); | |
| 13067 expect(_findIdentifier('paramCall').staticType.toString(), "int"); | |
| 13068 expect(_findIdentifier('lambdaCall').staticType.toString(), "int"); | |
| 13069 } | |
| 13070 | |
| 13071 void fail_genericMethod_functionExpressionInvocation_inferred() { | |
| 13072 _resolveTestUnit(r''' | |
| 13073 class C<E> { | |
| 13074 /*=T*/ f/*<T>*/(/*=T*/ e) => null; | |
| 13075 static /*=T*/ g/*<T>*/(/*=T*/ e) => null; | |
| 13076 static final h = g; | |
| 13077 } | |
| 13078 | |
| 13079 /*=T*/ topF/*<T>*/(/*=T*/ e) => null; | |
| 13080 var topG = topF; | |
| 13081 void test/*<S>*/(/*=T*/ pf/*<T>*/(/*=T*/ e)) { | |
| 13082 var c = new C<int>(); | |
| 13083 /*=T*/ lf/*<T>*/(/*=T*/ e) => null; | |
| 13084 | |
| 13085 var lambdaCall = (/*<E>*/(/*=E*/ e) => e)(3); | |
| 13086 var methodCall = (c.f)(3); | |
| 13087 var staticCall = (C.g)(3); | |
| 13088 var staticFieldCall = (C.h)(3); | |
| 13089 var topFunCall = (topF)(3); | |
| 13090 var topFieldCall = (topG)(3); | |
| 13091 var localCall = (lf)(3); | |
| 13092 var paramCall = (pf)(3); | |
| 13093 } | |
| 13094 '''); | |
| 13095 expect(_findIdentifier('methodCall').staticType.toString(), "int"); | |
| 13096 expect(_findIdentifier('staticCall').staticType.toString(), "int"); | |
| 13097 expect(_findIdentifier('staticFieldCall').staticType.toString(), "int"); | |
| 13098 expect(_findIdentifier('topFunCall').staticType.toString(), "int"); | |
| 13099 expect(_findIdentifier('topFieldCall').staticType.toString(), "int"); | |
| 13100 expect(_findIdentifier('localCall').staticType.toString(), "int"); | |
| 13101 expect(_findIdentifier('paramCall').staticType.toString(), "int"); | |
| 13102 expect(_findIdentifier('lambdaCall').staticType.toString(), "int"); | |
| 13103 } | |
| 13104 | |
| 13105 void fail_genericMethod_functionInvocation_inferred() { | |
| 13106 _resolveTestUnit(r''' | |
| 13107 class C<E> { | |
| 13108 /*=T*/ f/*<T>*/(/*=T*/ e) => null; | |
| 13109 static /*=T*/ g/*<T>*/(/*=T*/ e) => null; | |
| 13110 static final h = g; | |
| 13111 } | |
| 13112 | |
| 13113 /*=T*/ topF/*<T>*/(/*=T*/ e) => null; | |
| 13114 var topG = topF; | |
| 13115 void test/*<S>*/(/*=T*/ pf/*<T>*/(/*=T*/ e)) { | |
| 13116 var c = new C<int>(); | |
| 13117 /*=T*/ lf/*<T>*/(/*=T*/ e) => null; | |
| 13118 var methodCall = c.f(3); | |
| 13119 var staticCall = C.g(3); | |
| 13120 var staticFieldCall = C.h(3); | |
| 13121 var topFunCall = topF(3); | |
| 13122 var topFieldCall = topG(3); | |
| 13123 var localCall = lf(3); | |
| 13124 var paramCall = pf(3); | |
| 13125 } | |
| 13126 '''); | |
| 13127 expect(_findIdentifier('methodCall').staticType.toString(), "int"); | |
| 13128 expect(_findIdentifier('staticCall').staticType.toString(), "int"); | |
| 13129 expect(_findIdentifier('staticFieldCall').staticType.toString(), "int"); | |
| 13130 expect(_findIdentifier('topFunCall').staticType.toString(), "int"); | |
| 13131 expect(_findIdentifier('topFieldCall').staticType.toString(), "int"); | |
| 13132 expect(_findIdentifier('localCall').staticType.toString(), "int"); | |
| 13133 expect(_findIdentifier('paramCall').staticType.toString(), "int"); | |
| 13134 } | |
| 13135 | |
| 13136 void fail_genericMethod_tearoff_instantiated() { | 13037 void fail_genericMethod_tearoff_instantiated() { |
| 13137 _resolveTestUnit(r''' | 13038 _resolveTestUnit(r''' |
| 13138 class C<E> { | 13039 class C<E> { |
| 13139 /*=T*/ f/*<T>*/(E e) => null; | 13040 /*=T*/ f/*<T>*/(E e) => null; |
| 13140 static /*=T*/ g/*<T>*/(/*=T*/ e) => null; | 13041 static /*=T*/ g/*<T>*/(/*=T*/ e) => null; |
| 13141 static final h = g; | 13042 static final h = g; |
| 13142 } | 13043 } |
| 13143 | 13044 |
| 13144 /*=T*/ topF/*<T>*/(/*=T*/ e) => null; | 13045 /*=T*/ topF/*<T>*/(/*=T*/ e) => null; |
| 13145 var topG = topF; | 13046 var topG = topF; |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13381 MethodInvocation f = _findIdentifier('f/*<int>*/').parent; | 13282 MethodInvocation f = _findIdentifier('f/*<int>*/').parent; |
| 13382 FunctionType ft = f.staticInvokeType; | 13283 FunctionType ft = f.staticInvokeType; |
| 13383 expect(ft.toString(), '(String) → List<int>'); | 13284 expect(ft.toString(), '(String) → List<int>'); |
| 13384 expect('${ft.typeArguments}/${ft.typeParameters}', '[String, int]/[E, T]'); | 13285 expect('${ft.typeArguments}/${ft.typeParameters}', '[String, int]/[E, T]'); |
| 13385 | 13286 |
| 13386 SimpleIdentifier x = _findIdentifier('x'); | 13287 SimpleIdentifier x = _findIdentifier('x'); |
| 13387 expect(x.staticType, | 13288 expect(x.staticType, |
| 13388 typeProvider.listType.substitute4([typeProvider.intType])); | 13289 typeProvider.listType.substitute4([typeProvider.intType])); |
| 13389 } | 13290 } |
| 13390 | 13291 |
| 13292 void test_genericMethod_functionExpressionInvocation_explicit() { |
| 13293 _resolveTestUnit(r''' |
| 13294 class C<E> { |
| 13295 /*=T*/ f/*<T>*/(/*=T*/ e) => null; |
| 13296 static /*=T*/ g/*<T>*/(/*=T*/ e) => null; |
| 13297 static final h = g; |
| 13298 } |
| 13299 |
| 13300 /*=T*/ topF/*<T>*/(/*=T*/ e) => null; |
| 13301 var topG = topF; |
| 13302 void test/*<S>*/(/*=T*/ pf/*<T>*/(/*=T*/ e)) { |
| 13303 var c = new C<int>(); |
| 13304 /*=T*/ lf/*<T>*/(/*=T*/ e) => null; |
| 13305 |
| 13306 var lambdaCall = (/*<E>*/(/*=E*/ e) => e)/*<int>*/(3); |
| 13307 var methodCall = (c.f)/*<int>*/(3); |
| 13308 var staticCall = (C.g)/*<int>*/(3); |
| 13309 var staticFieldCall = (C.h)/*<int>*/(3); |
| 13310 var topFunCall = (topF)/*<int>*/(3); |
| 13311 var topFieldCall = (topG)/*<int>*/(3); |
| 13312 var localCall = (lf)/*<int>*/(3); |
| 13313 var paramCall = (pf)/*<int>*/(3); |
| 13314 } |
| 13315 '''); |
| 13316 expect(_findIdentifier('methodCall').staticType.toString(), "int"); |
| 13317 expect(_findIdentifier('staticCall').staticType.toString(), "int"); |
| 13318 expect(_findIdentifier('staticFieldCall').staticType.toString(), "int"); |
| 13319 expect(_findIdentifier('topFunCall').staticType.toString(), "int"); |
| 13320 expect(_findIdentifier('topFieldCall').staticType.toString(), "int"); |
| 13321 expect(_findIdentifier('localCall').staticType.toString(), "int"); |
| 13322 expect(_findIdentifier('paramCall').staticType.toString(), "int"); |
| 13323 expect(_findIdentifier('lambdaCall').staticType.toString(), "int"); |
| 13324 } |
| 13325 |
| 13326 void test_genericMethod_functionExpressionInvocation_inferred() { |
| 13327 _resolveTestUnit(r''' |
| 13328 class C<E> { |
| 13329 /*=T*/ f/*<T>*/(/*=T*/ e) => null; |
| 13330 static /*=T*/ g/*<T>*/(/*=T*/ e) => null; |
| 13331 static final h = g; |
| 13332 } |
| 13333 |
| 13334 /*=T*/ topF/*<T>*/(/*=T*/ e) => null; |
| 13335 var topG = topF; |
| 13336 void test/*<S>*/(/*=T*/ pf/*<T>*/(/*=T*/ e)) { |
| 13337 var c = new C<int>(); |
| 13338 /*=T*/ lf/*<T>*/(/*=T*/ e) => null; |
| 13339 |
| 13340 var lambdaCall = (/*<E>*/(/*=E*/ e) => e)(3); |
| 13341 var methodCall = (c.f)(3); |
| 13342 var staticCall = (C.g)(3); |
| 13343 var staticFieldCall = (C.h)(3); |
| 13344 var topFunCall = (topF)(3); |
| 13345 var topFieldCall = (topG)(3); |
| 13346 var localCall = (lf)(3); |
| 13347 var paramCall = (pf)(3); |
| 13348 } |
| 13349 '''); |
| 13350 expect(_findIdentifier('methodCall').staticType.toString(), "int"); |
| 13351 expect(_findIdentifier('staticCall').staticType.toString(), "int"); |
| 13352 expect(_findIdentifier('staticFieldCall').staticType.toString(), "int"); |
| 13353 expect(_findIdentifier('topFunCall').staticType.toString(), "int"); |
| 13354 expect(_findIdentifier('topFieldCall').staticType.toString(), "int"); |
| 13355 expect(_findIdentifier('localCall').staticType.toString(), "int"); |
| 13356 expect(_findIdentifier('paramCall').staticType.toString(), "int"); |
| 13357 expect(_findIdentifier('lambdaCall').staticType.toString(), "int"); |
| 13358 } |
| 13359 |
| 13391 void test_genericMethod_functionInvocation_explicit() { | 13360 void test_genericMethod_functionInvocation_explicit() { |
| 13392 _resolveTestUnit(r''' | 13361 _resolveTestUnit(r''' |
| 13393 class C<E> { | 13362 class C<E> { |
| 13394 /*=T*/ f/*<T>*/(/*=T*/ e) => null; | 13363 /*=T*/ f/*<T>*/(/*=T*/ e) => null; |
| 13395 static /*=T*/ g/*<T>*/(/*=T*/ e) => null; | 13364 static /*=T*/ g/*<T>*/(/*=T*/ e) => null; |
| 13396 static final h = g; | 13365 static final h = g; |
| 13397 } | 13366 } |
| 13398 | 13367 |
| 13399 /*=T*/ topF/*<T>*/(/*=T*/ e) => null; | 13368 /*=T*/ topF/*<T>*/(/*=T*/ e) => null; |
| 13400 var topG = topF; | 13369 var topG = topF; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 13412 '''); | 13381 '''); |
| 13413 expect(_findIdentifier('methodCall').staticType.toString(), "int"); | 13382 expect(_findIdentifier('methodCall').staticType.toString(), "int"); |
| 13414 expect(_findIdentifier('staticCall').staticType.toString(), "int"); | 13383 expect(_findIdentifier('staticCall').staticType.toString(), "int"); |
| 13415 expect(_findIdentifier('staticFieldCall').staticType.toString(), "int"); | 13384 expect(_findIdentifier('staticFieldCall').staticType.toString(), "int"); |
| 13416 expect(_findIdentifier('topFunCall').staticType.toString(), "int"); | 13385 expect(_findIdentifier('topFunCall').staticType.toString(), "int"); |
| 13417 expect(_findIdentifier('topFieldCall').staticType.toString(), "int"); | 13386 expect(_findIdentifier('topFieldCall').staticType.toString(), "int"); |
| 13418 expect(_findIdentifier('localCall').staticType.toString(), "int"); | 13387 expect(_findIdentifier('localCall').staticType.toString(), "int"); |
| 13419 expect(_findIdentifier('paramCall').staticType.toString(), "int"); | 13388 expect(_findIdentifier('paramCall').staticType.toString(), "int"); |
| 13420 } | 13389 } |
| 13421 | 13390 |
| 13391 void test_genericMethod_functionInvocation_inferred() { |
| 13392 _resolveTestUnit(r''' |
| 13393 class C<E> { |
| 13394 /*=T*/ f/*<T>*/(/*=T*/ e) => null; |
| 13395 static /*=T*/ g/*<T>*/(/*=T*/ e) => null; |
| 13396 static final h = g; |
| 13397 } |
| 13398 |
| 13399 /*=T*/ topF/*<T>*/(/*=T*/ e) => null; |
| 13400 var topG = topF; |
| 13401 void test/*<S>*/(/*=T*/ pf/*<T>*/(/*=T*/ e)) { |
| 13402 var c = new C<int>(); |
| 13403 /*=T*/ lf/*<T>*/(/*=T*/ e) => null; |
| 13404 var methodCall = c.f(3); |
| 13405 var staticCall = C.g(3); |
| 13406 var staticFieldCall = C.h(3); |
| 13407 var topFunCall = topF(3); |
| 13408 var topFieldCall = topG(3); |
| 13409 var localCall = lf(3); |
| 13410 var paramCall = pf(3); |
| 13411 } |
| 13412 '''); |
| 13413 expect(_findIdentifier('methodCall').staticType.toString(), "int"); |
| 13414 expect(_findIdentifier('staticCall').staticType.toString(), "int"); |
| 13415 expect(_findIdentifier('staticFieldCall').staticType.toString(), "int"); |
| 13416 expect(_findIdentifier('topFunCall').staticType.toString(), "int"); |
| 13417 expect(_findIdentifier('topFieldCall').staticType.toString(), "int"); |
| 13418 expect(_findIdentifier('localCall').staticType.toString(), "int"); |
| 13419 expect(_findIdentifier('paramCall').staticType.toString(), "int"); |
| 13420 } |
| 13421 |
| 13422 void test_genericMethod_functionTypedParameter() { | 13422 void test_genericMethod_functionTypedParameter() { |
| 13423 _resolveTestUnit(r''' | 13423 _resolveTestUnit(r''' |
| 13424 class C<E> { | 13424 class C<E> { |
| 13425 List/*<T>*/ f/*<T>*/(/*=T*/ f(E e)) => null; | 13425 List/*<T>*/ f/*<T>*/(/*=T*/ f(E e)) => null; |
| 13426 } | 13426 } |
| 13427 main() { | 13427 main() { |
| 13428 C<String> cOfString; | 13428 C<String> cOfString; |
| 13429 } | 13429 } |
| 13430 '''); | 13430 '''); |
| 13431 SimpleIdentifier f = _findIdentifier('f'); | 13431 SimpleIdentifier f = _findIdentifier('f'); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 13453 } | 13453 } |
| 13454 void foo() { | 13454 void foo() { |
| 13455 List list = null; | 13455 List list = null; |
| 13456 list.map((e) => e); | 13456 list.map((e) => e); |
| 13457 list.map((e) => 3); | 13457 list.map((e) => 3); |
| 13458 }'''); | 13458 }'''); |
| 13459 | 13459 |
| 13460 SimpleIdentifier map1 = _findIdentifier('map((e) => e);'); | 13460 SimpleIdentifier map1 = _findIdentifier('map((e) => e);'); |
| 13461 MethodInvocation m1 = map1.parent; | 13461 MethodInvocation m1 = map1.parent; |
| 13462 expect(m1.staticInvokeType.toString(), '((dynamic) → dynamic) → dynamic'); | 13462 expect(m1.staticInvokeType.toString(), '((dynamic) → dynamic) → dynamic'); |
| 13463 expect(map1.staticType, isNull); | 13463 expect(map1.staticType.toString(), '<T>((dynamic) → T) → T'); |
| 13464 expect(map1.propagatedType, isNull); | 13464 expect(map1.propagatedType, isNull); |
| 13465 SimpleIdentifier map2 = _findIdentifier('map((e) => 3);'); | 13465 SimpleIdentifier map2 = _findIdentifier('map((e) => 3);'); |
| 13466 MethodInvocation m2 = map2.parent; | 13466 MethodInvocation m2 = map2.parent; |
| 13467 expect(m2.staticInvokeType.toString(), '((dynamic) → int) → int'); | 13467 expect(m2.staticInvokeType.toString(), '((dynamic) → int) → int'); |
| 13468 expect(map2.staticType, isNull); | 13468 expect(map2.staticType.toString(), '<T>((dynamic) → T) → T'); |
| 13469 expect(map2.propagatedType, isNull); | 13469 expect(map2.propagatedType, isNull); |
| 13470 } | 13470 } |
| 13471 | 13471 |
| 13472 void test_genericMethod_nestedCapture() { | 13472 void test_genericMethod_nestedCapture() { |
| 13473 _resolveTestUnit(r''' | 13473 _resolveTestUnit(r''' |
| 13474 class C<T> { | 13474 class C<T> { |
| 13475 /*=T*/ f/*<S>*/(/*=S*/ x) { | 13475 /*=T*/ f/*<S>*/(/*=S*/ x) { |
| 13476 new C<S>().f/*<int>*/(3); | 13476 new C<S>().f/*<int>*/(3); |
| 13477 new C<S>().f; // tear-off | 13477 new C<S>().f; // tear-off |
| 13478 return null; | 13478 return null; |
| (...skipping 2265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15744 library helper; | 15744 library helper; |
| 15745 dynamic $name = (int x) => x + 42'); | 15745 dynamic $name = (int x) => x + 42'); |
| 15746 '''); | 15746 '''); |
| 15747 String code = ''' | 15747 String code = ''' |
| 15748 import 'helper.dart' as helper; | 15748 import 'helper.dart' as helper; |
| 15749 main() { | 15749 main() { |
| 15750 helper.$name(); // marker | 15750 helper.$name(); // marker |
| 15751 }'''; | 15751 }'''; |
| 15752 SimpleIdentifier methodName = _findMarkedIdentifier(code, "(); // marker"); | 15752 SimpleIdentifier methodName = _findMarkedIdentifier(code, "(); // marker"); |
| 15753 MethodInvocation methodInvoke = methodName.parent; | 15753 MethodInvocation methodInvoke = methodName.parent; |
| 15754 expect(methodName.staticType, null, reason: 'library prefix has no type'); | 15754 expect(methodName.staticType, typeProvider.dynamicType); |
| 15755 expect(methodInvoke.staticType, typeProvider.dynamicType); | 15755 expect(methodInvoke.staticType, typeProvider.dynamicType); |
| 15756 } | 15756 } |
| 15757 | 15757 |
| 15758 void test_objectMethodInference_disabled_for_local_function() { | 15758 void test_objectMethodInference_disabled_for_local_function() { |
| 15759 String name = 'toString'; | 15759 String name = 'toString'; |
| 15760 String code = ''' | 15760 String code = ''' |
| 15761 main() { | 15761 main() { |
| 15762 dynamic $name = () => null; | 15762 dynamic $name = () => null; |
| 15763 $name(); // marker | 15763 $name(); // marker |
| 15764 }'''; | 15764 }'''; |
| (...skipping 925 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 16690 | 16690 |
| 16691 void _resolveTestUnit(String code) { | 16691 void _resolveTestUnit(String code) { |
| 16692 testCode = code; | 16692 testCode = code; |
| 16693 testSource = addSource(testCode); | 16693 testSource = addSource(testCode); |
| 16694 LibraryElement library = resolve2(testSource); | 16694 LibraryElement library = resolve2(testSource); |
| 16695 assertNoErrors(testSource); | 16695 assertNoErrors(testSource); |
| 16696 verify([testSource]); | 16696 verify([testSource]); |
| 16697 testUnit = resolveCompilationUnit(testSource, library); | 16697 testUnit = resolveCompilationUnit(testSource, library); |
| 16698 } | 16698 } |
| 16699 } | 16699 } |
| OLD | NEW |