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 2258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2269 ConstructorElement constructor = constructors[0]; | 2269 ConstructorElement constructor = constructors[0]; |
2270 expect(constructor, isNotNull); | 2270 expect(constructor, isNotNull); |
2271 List<FunctionElement> functions = constructor.functions; | 2271 List<FunctionElement> functions = constructor.functions; |
2272 expect(functions, isNotNull); | 2272 expect(functions, isNotNull); |
2273 expect(functions, hasLength(1)); | 2273 expect(functions, hasLength(1)); |
2274 expect(functions[0].enclosingElement, constructor); | 2274 expect(functions[0].enclosingElement, constructor); |
2275 assertErrors(source, [ParserErrorCode.GETTER_IN_FUNCTION]); | 2275 assertErrors(source, [ParserErrorCode.GETTER_IN_FUNCTION]); |
2276 } | 2276 } |
2277 } | 2277 } |
2278 | 2278 |
| 2279 /** |
| 2280 * Tests for generic method and function resolution that do not use strong mode. |
| 2281 */ |
| 2282 @reflectiveTest |
| 2283 class GenericMethodResolverTest extends _StaticTypeAnalyzer2TestShared { |
| 2284 void setUp() { |
| 2285 super.setUp(); |
| 2286 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); |
| 2287 options.enableGenericMethods = true; |
| 2288 resetWithOptions(options); |
| 2289 } |
| 2290 |
| 2291 void test_genericMethod_propagatedType_promotion() { |
| 2292 // Regression test for: |
| 2293 // https://github.com/dart-lang/sdk/issues/25340 |
| 2294 // |
| 2295 // Note, after https://github.com/dart-lang/sdk/issues/25486 the original |
| 2296 // strong mode example won't work, as we now compute a static type and |
| 2297 // therefore discard the propagated type. |
| 2298 // |
| 2299 // So this test does not use strong mode. |
| 2300 _resolveTestUnit(r''' |
| 2301 abstract class Iter { |
| 2302 List<S> map<S>(S f(x)); |
| 2303 } |
| 2304 class C {} |
| 2305 C toSpan(dynamic element) { |
| 2306 if (element is Iter) { |
| 2307 var y = element.map(toSpan); |
| 2308 } |
| 2309 return null; |
| 2310 }'''); |
| 2311 SimpleIdentifier y = _findIdentifier('y = '); |
| 2312 expect(y.staticType.toString(), 'dynamic'); |
| 2313 expect(y.propagatedType.toString(), 'List<dynamic>'); |
| 2314 } |
| 2315 } |
| 2316 |
2279 @reflectiveTest | 2317 @reflectiveTest |
2280 class HintCodeTest extends ResolverTestCase { | 2318 class HintCodeTest extends ResolverTestCase { |
2281 void fail_deadCode_statementAfterRehrow() { | 2319 void fail_deadCode_statementAfterRehrow() { |
2282 Source source = addSource(r''' | 2320 Source source = addSource(r''' |
2283 f() { | 2321 f() { |
2284 try { | 2322 try { |
2285 var one = 1; | 2323 var one = 1; |
2286 } catch (e) { | 2324 } catch (e) { |
2287 rethrow; | 2325 rethrow; |
2288 var two = 2; | 2326 var two = 2; |
(...skipping 11300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13589 expect(errors.map((e) => e.errorCode.name), [ | 13627 expect(errors.map((e) => e.errorCode.name), [ |
13590 'STRONG_MODE_INVALID_METHOD_OVERRIDE', | 13628 'STRONG_MODE_INVALID_METHOD_OVERRIDE', |
13591 'INVALID_METHOD_OVERRIDE_TYPE_PARAMETERS' | 13629 'INVALID_METHOD_OVERRIDE_TYPE_PARAMETERS' |
13592 ]); | 13630 ]); |
13593 verify([source]); | 13631 verify([source]); |
13594 } | 13632 } |
13595 | 13633 |
13596 void test_genericMethod_propagatedType_promotion() { | 13634 void test_genericMethod_propagatedType_promotion() { |
13597 // Regression test for: | 13635 // Regression test for: |
13598 // https://github.com/dart-lang/sdk/issues/25340 | 13636 // https://github.com/dart-lang/sdk/issues/25340 |
| 13637 |
| 13638 // Note, after https://github.com/dart-lang/sdk/issues/25486 the original |
| 13639 // example won't work, as we now compute a static type and therefore discard |
| 13640 // the propagated type. So a new test was created that doesn't run under |
| 13641 // strong mode. |
13599 _resolveTestUnit(r''' | 13642 _resolveTestUnit(r''' |
13600 abstract class Iter { | 13643 abstract class Iter { |
13601 List/*<S>*/ map/*<S>*/(/*=S*/ f(x)); | 13644 List/*<S>*/ map/*<S>*/(/*=S*/ f(x)); |
13602 } | 13645 } |
13603 class C {} | 13646 class C {} |
13604 C toSpan(dynamic element) { | 13647 C toSpan(dynamic element) { |
13605 if (element is Iter) { | 13648 if (element is Iter) { |
13606 var y = element.map(toSpan); | 13649 var y = element.map(toSpan); |
13607 } | 13650 } |
13608 return null; | 13651 return null; |
13609 }'''); | 13652 }'''); |
13610 SimpleIdentifier y = _findIdentifier('y = '); | 13653 SimpleIdentifier y = _findIdentifier('y = '); |
13611 expect(y.staticType.toString(), 'dynamic'); | 13654 expect(y.staticType.toString(), 'List<C>'); |
13612 expect(y.propagatedType.toString(), 'List<dynamic>'); | 13655 expect(y.propagatedType, isNull); |
13613 } | 13656 } |
13614 | 13657 |
13615 void test_genericMethod_tearoff() { | 13658 void test_genericMethod_tearoff() { |
13616 _resolveTestUnit(r''' | 13659 _resolveTestUnit(r''' |
13617 class C<E> { | 13660 class C<E> { |
13618 /*=T*/ f/*<T>*/(E e) => null; | 13661 /*=T*/ f/*<T>*/(E e) => null; |
13619 static /*=T*/ g/*<T>*/(/*=T*/ e) => null; | 13662 static /*=T*/ g/*<T>*/(/*=T*/ e) => null; |
13620 static final h = g; | 13663 static final h = g; |
13621 } | 13664 } |
13622 | 13665 |
(...skipping 3086 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16709 | 16752 |
16710 void _resolveTestUnit(String code) { | 16753 void _resolveTestUnit(String code) { |
16711 testCode = code; | 16754 testCode = code; |
16712 testSource = addSource(testCode); | 16755 testSource = addSource(testCode); |
16713 LibraryElement library = resolve2(testSource); | 16756 LibraryElement library = resolve2(testSource); |
16714 assertNoErrors(testSource); | 16757 assertNoErrors(testSource); |
16715 verify([testSource]); | 16758 verify([testSource]); |
16716 testUnit = resolveCompilationUnit(testSource, library); | 16759 testUnit = resolveCompilationUnit(testSource, library); |
16717 } | 16760 } |
16718 } | 16761 } |
OLD | NEW |