| 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() { | 13037 void fail_genericMethod_functionExpressionInvocation_inferred() { |
| 13072 _resolveTestUnit(r''' | 13038 _resolveTestUnit(r''' |
| 13073 class C<E> { | 13039 class C<E> { |
| 13074 /*=T*/ f/*<T>*/(/*=T*/ e) => null; | 13040 /*=T*/ f/*<T>*/(/*=T*/ e) => null; |
| 13075 static /*=T*/ g/*<T>*/(/*=T*/ e) => null; | 13041 static /*=T*/ g/*<T>*/(/*=T*/ e) => null; |
| 13076 static final h = g; | 13042 static final h = g; |
| 13077 } | 13043 } |
| 13078 | 13044 |
| 13079 /*=T*/ topF/*<T>*/(/*=T*/ e) => null; | 13045 /*=T*/ topF/*<T>*/(/*=T*/ e) => null; |
| 13080 var topG = topF; | 13046 var topG = topF; |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13381 MethodInvocation f = _findIdentifier('f/*<int>*/').parent; | 13347 MethodInvocation f = _findIdentifier('f/*<int>*/').parent; |
| 13382 FunctionType ft = f.staticInvokeType; | 13348 FunctionType ft = f.staticInvokeType; |
| 13383 expect(ft.toString(), '(String) → List<int>'); | 13349 expect(ft.toString(), '(String) → List<int>'); |
| 13384 expect('${ft.typeArguments}/${ft.typeParameters}', '[String, int]/[E, T]'); | 13350 expect('${ft.typeArguments}/${ft.typeParameters}', '[String, int]/[E, T]'); |
| 13385 | 13351 |
| 13386 SimpleIdentifier x = _findIdentifier('x'); | 13352 SimpleIdentifier x = _findIdentifier('x'); |
| 13387 expect(x.staticType, | 13353 expect(x.staticType, |
| 13388 typeProvider.listType.substitute4([typeProvider.intType])); | 13354 typeProvider.listType.substitute4([typeProvider.intType])); |
| 13389 } | 13355 } |
| 13390 | 13356 |
| 13357 void test_genericMethod_functionExpressionInvocation_explicit() { |
| 13358 _resolveTestUnit(r''' |
| 13359 class C<E> { |
| 13360 /*=T*/ f/*<T>*/(/*=T*/ e) => null; |
| 13361 static /*=T*/ g/*<T>*/(/*=T*/ e) => null; |
| 13362 static final h = g; |
| 13363 } |
| 13364 |
| 13365 /*=T*/ topF/*<T>*/(/*=T*/ e) => null; |
| 13366 var topG = topF; |
| 13367 void test/*<S>*/(/*=T*/ pf/*<T>*/(/*=T*/ e)) { |
| 13368 var c = new C<int>(); |
| 13369 /*=T*/ lf/*<T>*/(/*=T*/ e) => null; |
| 13370 |
| 13371 var lambdaCall = (/*<E>*/(/*=E*/ e) => e)/*<int>*/(3); |
| 13372 var methodCall = (c.f)/*<int>*/(3); |
| 13373 var staticCall = (C.g)/*<int>*/(3); |
| 13374 var staticFieldCall = (C.h)/*<int>*/(3); |
| 13375 var topFunCall = (topF)/*<int>*/(3); |
| 13376 var topFieldCall = (topG)/*<int>*/(3); |
| 13377 var localCall = (lf)/*<int>*/(3); |
| 13378 var paramCall = (pf)/*<int>*/(3); |
| 13379 } |
| 13380 '''); |
| 13381 expect(_findIdentifier('methodCall').staticType.toString(), "int"); |
| 13382 expect(_findIdentifier('staticCall').staticType.toString(), "int"); |
| 13383 expect(_findIdentifier('staticFieldCall').staticType.toString(), "int"); |
| 13384 expect(_findIdentifier('topFunCall').staticType.toString(), "int"); |
| 13385 expect(_findIdentifier('topFieldCall').staticType.toString(), "int"); |
| 13386 expect(_findIdentifier('localCall').staticType.toString(), "int"); |
| 13387 expect(_findIdentifier('paramCall').staticType.toString(), "int"); |
| 13388 expect(_findIdentifier('lambdaCall').staticType.toString(), "int"); |
| 13389 } |
| 13390 |
| 13391 void test_genericMethod_functionInvocation_explicit() { | 13391 void test_genericMethod_functionInvocation_explicit() { |
| 13392 _resolveTestUnit(r''' | 13392 _resolveTestUnit(r''' |
| 13393 class C<E> { | 13393 class C<E> { |
| 13394 /*=T*/ f/*<T>*/(/*=T*/ e) => null; | 13394 /*=T*/ f/*<T>*/(/*=T*/ e) => null; |
| 13395 static /*=T*/ g/*<T>*/(/*=T*/ e) => null; | 13395 static /*=T*/ g/*<T>*/(/*=T*/ e) => null; |
| 13396 static final h = g; | 13396 static final h = g; |
| 13397 } | 13397 } |
| 13398 | 13398 |
| 13399 /*=T*/ topF/*<T>*/(/*=T*/ e) => null; | 13399 /*=T*/ topF/*<T>*/(/*=T*/ e) => null; |
| 13400 var topG = topF; | 13400 var topG = topF; |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13586 // TODO(jmesserly): we can't use assertErrors because STRONG_MODE_* errors | 13586 // TODO(jmesserly): we can't use assertErrors because STRONG_MODE_* errors |
| 13587 // from CodeChecker don't have working equality. | 13587 // from CodeChecker don't have working equality. |
| 13588 List<AnalysisError> errors = analysisContext2.computeErrors(source); | 13588 List<AnalysisError> errors = analysisContext2.computeErrors(source); |
| 13589 expect(errors.map((e) => e.errorCode.name), [ | 13589 expect(errors.map((e) => e.errorCode.name), [ |
| 13590 'STRONG_MODE_INVALID_METHOD_OVERRIDE', | 13590 'STRONG_MODE_INVALID_METHOD_OVERRIDE', |
| 13591 'INVALID_METHOD_OVERRIDE_TYPE_PARAMETERS' | 13591 'INVALID_METHOD_OVERRIDE_TYPE_PARAMETERS' |
| 13592 ]); | 13592 ]); |
| 13593 verify([source]); | 13593 verify([source]); |
| 13594 } | 13594 } |
| 13595 | 13595 |
| 13596 void test_genericMethod_propagatedType_promotion() { |
| 13597 // Regression test for: |
| 13598 // https://github.com/dart-lang/sdk/issues/25340 |
| 13599 _resolveTestUnit(r''' |
| 13600 abstract class Iter { |
| 13601 List/*<S>*/ map/*<S>*/(/*=S*/ f(x)); |
| 13602 } |
| 13603 class C {} |
| 13604 C toSpan(dynamic element) { |
| 13605 if (element is Iter) { |
| 13606 var y = element.map(toSpan); |
| 13607 } |
| 13608 return null; |
| 13609 }'''); |
| 13610 SimpleIdentifier y = _findIdentifier('y = '); |
| 13611 expect(y.staticType.toString(), 'dynamic'); |
| 13612 expect(y.propagatedType.toString(), 'List<dynamic>'); |
| 13613 } |
| 13614 |
| 13596 void test_genericMethod_tearoff() { | 13615 void test_genericMethod_tearoff() { |
| 13597 _resolveTestUnit(r''' | 13616 _resolveTestUnit(r''' |
| 13598 class C<E> { | 13617 class C<E> { |
| 13599 /*=T*/ f/*<T>*/(E e) => null; | 13618 /*=T*/ f/*<T>*/(E e) => null; |
| 13600 static /*=T*/ g/*<T>*/(/*=T*/ e) => null; | 13619 static /*=T*/ g/*<T>*/(/*=T*/ e) => null; |
| 13601 static final h = g; | 13620 static final h = g; |
| 13602 } | 13621 } |
| 13603 | 13622 |
| 13604 /*=T*/ topF/*<T>*/(/*=T*/ e) => null; | 13623 /*=T*/ topF/*<T>*/(/*=T*/ e) => null; |
| 13605 var topG = topF; | 13624 var topG = topF; |
| (...skipping 3084 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 16690 | 16709 |
| 16691 void _resolveTestUnit(String code) { | 16710 void _resolveTestUnit(String code) { |
| 16692 testCode = code; | 16711 testCode = code; |
| 16693 testSource = addSource(testCode); | 16712 testSource = addSource(testCode); |
| 16694 LibraryElement library = resolve2(testSource); | 16713 LibraryElement library = resolve2(testSource); |
| 16695 assertNoErrors(testSource); | 16714 assertNoErrors(testSource); |
| 16696 verify([testSource]); | 16715 verify([testSource]); |
| 16697 testUnit = resolveCompilationUnit(testSource, library); | 16716 testUnit = resolveCompilationUnit(testSource, library); |
| 16698 } | 16717 } |
| 16699 } | 16718 } |
| OLD | NEW |