| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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.strong_mode_test; | |
| 6 | |
| 7 import 'dart:async'; | 5 import 'dart:async'; |
| 8 | 6 |
| 9 import 'package:analyzer/dart/ast/ast.dart'; | 7 import 'package:analyzer/dart/ast/ast.dart'; |
| 10 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; | 8 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; |
| 11 import 'package:analyzer/dart/element/element.dart'; | 9 import 'package:analyzer/dart/element/element.dart'; |
| 12 import 'package:analyzer/dart/element/type.dart'; | 10 import 'package:analyzer/dart/element/type.dart'; |
| 13 import 'package:analyzer/src/dart/element/element.dart'; | 11 import 'package:analyzer/src/dart/element/element.dart'; |
| 14 import 'package:analyzer/src/error/codes.dart'; | 12 import 'package:analyzer/src/error/codes.dart'; |
| 15 import 'package:analyzer/src/generated/engine.dart'; | 13 import 'package:analyzer/src/generated/engine.dart'; |
| 16 import 'package:analyzer/src/generated/source_io.dart'; | 14 import 'package:analyzer/src/generated/source_io.dart'; |
| (...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 expect(covariantC.toList(), [cAdd.element.parameters[0]]); | 471 expect(covariantC.toList(), [cAdd.element.parameters[0]]); |
| 474 | 472 |
| 475 var dAdd = AstFinder.getMethodInClass(unit, "D", "add"); | 473 var dAdd = AstFinder.getMethodInClass(unit, "D", "add"); |
| 476 var covariantD = getClassCovariantParameters(AstFinder.getClass(unit, "D")); | 474 var covariantD = getClassCovariantParameters(AstFinder.getClass(unit, "D")); |
| 477 expect(covariantD.toList(), [dAdd.element.parameters[0]]); | 475 expect(covariantD.toList(), [dAdd.element.parameters[0]]); |
| 478 | 476 |
| 479 var covariantE = getClassCovariantParameters(AstFinder.getClass(unit, "E")); | 477 var covariantE = getClassCovariantParameters(AstFinder.getClass(unit, "E")); |
| 480 expect(covariantE.toList(), []); | 478 expect(covariantE.toList(), []); |
| 481 } | 479 } |
| 482 | 480 |
| 483 test_covarianceChecks_superclass() async { | |
| 484 var source = addSource(r''' | |
| 485 class C<T> { | |
| 486 add(T t) {} | |
| 487 forEach(void f(T t)) {} | |
| 488 } | |
| 489 class D { | |
| 490 add(int t) {} | |
| 491 forEach(void f(int t)) {} | |
| 492 } | |
| 493 class E extends D implements C<int> {} | |
| 494 '''); | |
| 495 var unit = (await computeAnalysisResult(source)).unit; | |
| 496 assertNoErrors(source); | |
| 497 var cAdd = AstFinder.getMethodInClass(unit, "C", "add"); | |
| 498 var covariantC = getClassCovariantParameters(AstFinder.getClass(unit, "C")); | |
| 499 expect(covariantC.toList(), [cAdd.element.parameters[0]]); | |
| 500 | |
| 501 var dAdd = AstFinder.getMethodInClass(unit, "D", "add"); | |
| 502 var covariantD = getClassCovariantParameters(AstFinder.getClass(unit, "D")); | |
| 503 expect(covariantD, null); | |
| 504 | |
| 505 var classE = AstFinder.getClass(unit, "E"); | |
| 506 var covariantE = getClassCovariantParameters(classE); | |
| 507 var superCovariantE = getSuperclassCovariantParameters(classE); | |
| 508 expect(covariantE.toList(), []); | |
| 509 expect(superCovariantE.toList(), [dAdd.element.parameters[0]]); | |
| 510 } | |
| 511 | |
| 512 test_covarianceChecks_returnFunction() async { | 481 test_covarianceChecks_returnFunction() async { |
| 513 var source = addSource(r''' | 482 var source = addSource(r''' |
| 514 typedef F<T>(T t); | 483 typedef F<T>(T t); |
| 515 typedef T R<T>(); | 484 typedef T R<T>(); |
| 516 class C<T> { | 485 class C<T> { |
| 517 F<T> f; | 486 F<T> f; |
| 518 | 487 |
| 519 C(); | 488 C(); |
| 520 factory C.fact() => new C<Null>(); | 489 factory C.fact() => new C<Null>(); |
| 521 | 490 |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 707 expectCast(s, false); | 676 expectCast(s, false); |
| 708 } | 677 } |
| 709 for (var s in AstFinder.getStatementsInTopLevelFunction(unit, 'noCasts')) { | 678 for (var s in AstFinder.getStatementsInTopLevelFunction(unit, 'noCasts')) { |
| 710 expectCast(s, false); | 679 expectCast(s, false); |
| 711 } | 680 } |
| 712 for (var s in AstFinder.getStatementsInTopLevelFunction(unit, 'casts')) { | 681 for (var s in AstFinder.getStatementsInTopLevelFunction(unit, 'casts')) { |
| 713 expectCast(s, true); | 682 expectCast(s, true); |
| 714 } | 683 } |
| 715 } | 684 } |
| 716 | 685 |
| 686 test_covarianceChecks_superclass() async { |
| 687 var source = addSource(r''' |
| 688 class C<T> { |
| 689 add(T t) {} |
| 690 forEach(void f(T t)) {} |
| 691 } |
| 692 class D { |
| 693 add(int t) {} |
| 694 forEach(void f(int t)) {} |
| 695 } |
| 696 class E extends D implements C<int> {} |
| 697 '''); |
| 698 var unit = (await computeAnalysisResult(source)).unit; |
| 699 assertNoErrors(source); |
| 700 var cAdd = AstFinder.getMethodInClass(unit, "C", "add"); |
| 701 var covariantC = getClassCovariantParameters(AstFinder.getClass(unit, "C")); |
| 702 expect(covariantC.toList(), [cAdd.element.parameters[0]]); |
| 703 |
| 704 var dAdd = AstFinder.getMethodInClass(unit, "D", "add"); |
| 705 var covariantD = getClassCovariantParameters(AstFinder.getClass(unit, "D")); |
| 706 expect(covariantD, null); |
| 707 |
| 708 var classE = AstFinder.getClass(unit, "E"); |
| 709 var covariantE = getClassCovariantParameters(classE); |
| 710 var superCovariantE = getSuperclassCovariantParameters(classE); |
| 711 expect(covariantE.toList(), []); |
| 712 expect(superCovariantE.toList(), [dAdd.element.parameters[0]]); |
| 713 } |
| 714 |
| 717 test_factoryConstructor_propagation() async { | 715 test_factoryConstructor_propagation() async { |
| 718 String code = r''' | 716 String code = r''' |
| 719 class A<T> { | 717 class A<T> { |
| 720 factory A() { return new B(); } | 718 factory A() { return new B(); } |
| 721 } | 719 } |
| 722 class B<S> extends A<S> {} | 720 class B<S> extends A<S> {} |
| 723 '''; | 721 '''; |
| 724 CompilationUnit unit = await resolveSource(code); | 722 CompilationUnit unit = await resolveSource(code); |
| 725 | 723 |
| 726 ConstructorDeclaration constructor = | 724 ConstructorDeclaration constructor = |
| (...skipping 1947 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2674 import "dart:async"; | 2672 import "dart:async"; |
| 2675 dynamic test<T extends num>(FutureOr<T> x) => (x is T) && | 2673 dynamic test<T extends num>(FutureOr<T> x) => (x is T) && |
| 2676 (x.abs() == 0); | 2674 (x.abs() == 0); |
| 2677 '''; | 2675 '''; |
| 2678 await resolveTestUnit(code); | 2676 await resolveTestUnit(code); |
| 2679 } | 2677 } |
| 2680 | 2678 |
| 2681 fail_genericMethod_tearoff_instantiated() async { | 2679 fail_genericMethod_tearoff_instantiated() async { |
| 2682 await resolveTestUnit(r''' | 2680 await resolveTestUnit(r''' |
| 2683 class C<E> { | 2681 class C<E> { |
| 2684 /*=T*/ f/*<T>*/(E e) => null; | 2682 T f<T>(E e) => null; |
| 2685 static /*=T*/ g/*<T>*/(/*=T*/ e) => null; | 2683 static T g<T>(T e) => null; |
| 2686 static final h = g; | 2684 static final h = g; |
| 2687 } | 2685 } |
| 2688 | 2686 |
| 2689 /*=T*/ topF/*<T>*/(/*=T*/ e) => null; | 2687 T topF<T>(T e) => null; |
| 2690 var topG = topF; | 2688 var topG = topF; |
| 2691 void test/*<S>*/(/*=T*/ pf/*<T>*/(/*=T*/ e)) { | 2689 void test<S>(T pf<T>(T e)) { |
| 2692 var c = new C<int>(); | 2690 var c = new C<int>(); |
| 2693 /*=T*/ lf/*<T>*/(/*=T*/ e) => null; | 2691 T lf<T>(T e) => null; |
| 2694 var methodTearOffInst = c.f/*<int>*/; | 2692 var methodTearOffInst = c.f<int>; |
| 2695 var staticTearOffInst = C.g/*<int>*/; | 2693 var staticTearOffInst = C.g<int>; |
| 2696 var staticFieldTearOffInst = C.h/*<int>*/; | 2694 var staticFieldTearOffInst = C.h<int>; |
| 2697 var topFunTearOffInst = topF/*<int>*/; | 2695 var topFunTearOffInst = topF<int>; |
| 2698 var topFieldTearOffInst = topG/*<int>*/; | 2696 var topFieldTearOffInst = topG<int>; |
| 2699 var localTearOffInst = lf/*<int>*/; | 2697 var localTearOffInst = lf<int>; |
| 2700 var paramTearOffInst = pf/*<int>*/; | 2698 var paramTearOffInst = pf<int>; |
| 2701 } | 2699 } |
| 2702 '''); | 2700 '''); |
| 2703 expectIdentifierType('methodTearOffInst', "(int) → int"); | 2701 expectIdentifierType('methodTearOffInst', "(int) → int"); |
| 2704 expectIdentifierType('staticTearOffInst', "(int) → int"); | 2702 expectIdentifierType('staticTearOffInst', "(int) → int"); |
| 2705 expectIdentifierType('staticFieldTearOffInst', "(int) → int"); | 2703 expectIdentifierType('staticFieldTearOffInst', "(int) → int"); |
| 2706 expectIdentifierType('topFunTearOffInst', "(int) → int"); | 2704 expectIdentifierType('topFunTearOffInst', "(int) → int"); |
| 2707 expectIdentifierType('topFieldTearOffInst', "(int) → int"); | 2705 expectIdentifierType('topFieldTearOffInst', "(int) → int"); |
| 2708 expectIdentifierType('localTearOffInst', "(int) → int"); | 2706 expectIdentifierType('localTearOffInst', "(int) → int"); |
| 2709 expectIdentifierType('paramTearOffInst', "(int) → int"); | 2707 expectIdentifierType('paramTearOffInst', "(int) → int"); |
| 2710 } | 2708 } |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2763 // parameters T | 2761 // parameters T |
| 2764 String code = r''' | 2762 String code = r''' |
| 2765 import "dart:async"; | 2763 import "dart:async"; |
| 2766 dynamic test<T extends num>(FutureOr<T> x) => (x is Future<T>) && | 2764 dynamic test<T extends num>(FutureOr<T> x) => (x is Future<T>) && |
| 2767 (x.then((x) => x) == null); | 2765 (x.then((x) => x) == null); |
| 2768 '''; | 2766 '''; |
| 2769 await resolveTestUnit(code); | 2767 await resolveTestUnit(code); |
| 2770 } | 2768 } |
| 2771 | 2769 |
| 2772 test_genericFunction() async { | 2770 test_genericFunction() async { |
| 2773 await resolveTestUnit(r'/*=T*/ f/*<T>*/(/*=T*/ x) => null;'); | 2771 await resolveTestUnit(r'T f<T>(T x) => null;'); |
| 2774 expectFunctionType('f', '<T>(T) → T', | 2772 expectFunctionType('f', '<T>(T) → T', |
| 2775 elementTypeParams: '[T]', typeFormals: '[T]'); | 2773 elementTypeParams: '[T]', typeFormals: '[T]'); |
| 2776 SimpleIdentifier f = findIdentifier('f'); | 2774 SimpleIdentifier f = findIdentifier('f'); |
| 2777 FunctionElementImpl e = f.staticElement; | 2775 FunctionElementImpl e = f.staticElement; |
| 2778 FunctionType ft = e.type.instantiate([typeProvider.stringType]); | 2776 FunctionType ft = e.type.instantiate([typeProvider.stringType]); |
| 2779 expect(ft.toString(), '(String) → String'); | 2777 expect(ft.toString(), '(String) → String'); |
| 2780 } | 2778 } |
| 2781 | 2779 |
| 2782 test_genericFunction_bounds() async { | 2780 test_genericFunction_bounds() async { |
| 2783 await resolveTestUnit(r'/*=T*/ f/*<T extends num>*/(/*=T*/ x) => null;'); | 2781 await resolveTestUnit(r'T f<T extends num>(T x) => null;'); |
| 2784 expectFunctionType('f', '<T extends num>(T) → T', | 2782 expectFunctionType('f', '<T extends num>(T) → T', |
| 2785 elementTypeParams: '[T extends num]', typeFormals: '[T extends num]'); | 2783 elementTypeParams: '[T extends num]', typeFormals: '[T extends num]'); |
| 2786 } | 2784 } |
| 2787 | 2785 |
| 2788 test_genericFunction_parameter() async { | 2786 test_genericFunction_parameter() async { |
| 2789 await resolveTestUnit(r''' | 2787 await resolveTestUnit(r''' |
| 2790 void g(/*=T*/ f/*<T>*/(/*=T*/ x)) {} | 2788 void g(T f<T>(T x)) {} |
| 2791 ''', noErrors: false // TODO(paulberry): remove when dartbug.com/28515 fixed. | 2789 ''', noErrors: false // TODO(paulberry): remove when dartbug.com/28515 fixed. |
| 2792 ); | 2790 ); |
| 2793 expectFunctionType('f', '<T>(T) → T', | 2791 expectFunctionType('f', '<T>(T) → T', |
| 2794 elementTypeParams: '[T]', typeFormals: '[T]'); | 2792 elementTypeParams: '[T]', typeFormals: '[T]'); |
| 2795 SimpleIdentifier f = findIdentifier('f'); | 2793 SimpleIdentifier f = findIdentifier('f'); |
| 2796 ParameterElementImpl e = f.staticElement; | 2794 ParameterElementImpl e = f.staticElement; |
| 2797 FunctionType type = e.type; | 2795 FunctionType type = e.type; |
| 2798 FunctionType ft = type.instantiate([typeProvider.stringType]); | 2796 FunctionType ft = type.instantiate([typeProvider.stringType]); |
| 2799 expect(ft.toString(), '(String) → String'); | 2797 expect(ft.toString(), '(String) → String'); |
| 2800 } | 2798 } |
| 2801 | 2799 |
| 2802 test_genericFunction_static() async { | 2800 test_genericFunction_static() async { |
| 2803 await resolveTestUnit(r''' | 2801 await resolveTestUnit(r''' |
| 2804 class C<E> { | 2802 class C<E> { |
| 2805 static /*=T*/ f/*<T>*/(/*=T*/ x) => null; | 2803 static T f<T>(T x) => null; |
| 2806 } | 2804 } |
| 2807 '''); | 2805 '''); |
| 2808 expectFunctionType('f', '<T>(T) → T', | 2806 expectFunctionType('f', '<T>(T) → T', |
| 2809 elementTypeParams: '[T]', typeFormals: '[T]'); | 2807 elementTypeParams: '[T]', typeFormals: '[T]'); |
| 2810 SimpleIdentifier f = findIdentifier('f'); | 2808 SimpleIdentifier f = findIdentifier('f'); |
| 2811 MethodElementImpl e = f.staticElement; | 2809 MethodElementImpl e = f.staticElement; |
| 2812 FunctionType ft = e.type.instantiate([typeProvider.stringType]); | 2810 FunctionType ft = e.type.instantiate([typeProvider.stringType]); |
| 2813 expect(ft.toString(), '(String) → String'); | 2811 expect(ft.toString(), '(String) → String'); |
| 2814 } | 2812 } |
| 2815 | 2813 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2878 expectInitializerType('aaa', 'List<Object>'); | 2876 expectInitializerType('aaa', 'List<Object>'); |
| 2879 expectInitializerType('bbb', 'List<Object>'); | 2877 expectInitializerType('bbb', 'List<Object>'); |
| 2880 expectInitializerType('ccc', 'List<Object>'); | 2878 expectInitializerType('ccc', 'List<Object>'); |
| 2881 expectInitializerType('ddd', 'List<Object>'); | 2879 expectInitializerType('ddd', 'List<Object>'); |
| 2882 expectInitializerType('eee', 'List<Object>'); | 2880 expectInitializerType('eee', 'List<Object>'); |
| 2883 } | 2881 } |
| 2884 | 2882 |
| 2885 test_genericMethod() async { | 2883 test_genericMethod() async { |
| 2886 await resolveTestUnit(r''' | 2884 await resolveTestUnit(r''' |
| 2887 class C<E> { | 2885 class C<E> { |
| 2888 List/*<T>*/ f/*<T>*/(E e) => null; | 2886 List<T> f<T>(E e) => null; |
| 2889 } | 2887 } |
| 2890 main() { | 2888 main() { |
| 2891 C<String> cOfString; | 2889 C<String> cOfString; |
| 2892 } | 2890 } |
| 2893 '''); | 2891 '''); |
| 2894 expectFunctionType('f', '<T>(E) → List<T>', | 2892 expectFunctionType('f', '<T>(E) → List<T>', |
| 2895 elementTypeParams: '[T]', | 2893 elementTypeParams: '[T]', |
| 2896 typeParams: '[E]', | 2894 typeParams: '[E]', |
| 2897 typeArgs: '[E]', | 2895 typeArgs: '[E]', |
| 2898 typeFormals: '[T]'); | 2896 typeFormals: '[T]'); |
| 2899 SimpleIdentifier c = findIdentifier('cOfString'); | 2897 SimpleIdentifier c = findIdentifier('cOfString'); |
| 2900 FunctionType ft = (c.staticType as InterfaceType).getMethod('f').type; | 2898 FunctionType ft = (c.staticType as InterfaceType).getMethod('f').type; |
| 2901 expect(ft.toString(), '<T>(String) → List<T>'); | 2899 expect(ft.toString(), '<T>(String) → List<T>'); |
| 2902 ft = ft.instantiate([typeProvider.intType]); | 2900 ft = ft.instantiate([typeProvider.intType]); |
| 2903 expect(ft.toString(), '(String) → List<int>'); | 2901 expect(ft.toString(), '(String) → List<int>'); |
| 2904 expect('${ft.typeArguments}/${ft.typeParameters}', '[String, int]/[E, T]'); | 2902 expect('${ft.typeArguments}/${ft.typeParameters}', '[String, int]/[E, T]'); |
| 2905 } | 2903 } |
| 2906 | 2904 |
| 2907 test_genericMethod_explicitTypeParams() async { | 2905 test_genericMethod_explicitTypeParams() async { |
| 2908 await resolveTestUnit(r''' | 2906 await resolveTestUnit(r''' |
| 2909 class C<E> { | 2907 class C<E> { |
| 2910 List/*<T>*/ f/*<T>*/(E e) => null; | 2908 List<T> f<T>(E e) => null; |
| 2911 } | 2909 } |
| 2912 main() { | 2910 main() { |
| 2913 C<String> cOfString; | 2911 C<String> cOfString; |
| 2914 var x = cOfString.f/*<int>*/('hi'); | 2912 var x = cOfString.f<int>('hi'); |
| 2915 } | 2913 } |
| 2916 '''); | 2914 '''); |
| 2917 MethodInvocation f = findIdentifier('f/*<int>*/').parent; | 2915 MethodInvocation f = findIdentifier('f<int>').parent; |
| 2918 FunctionType ft = f.staticInvokeType; | 2916 FunctionType ft = f.staticInvokeType; |
| 2919 expect(ft.toString(), '(String) → List<int>'); | 2917 expect(ft.toString(), '(String) → List<int>'); |
| 2920 expect('${ft.typeArguments}/${ft.typeParameters}', '[String, int]/[E, T]'); | 2918 expect('${ft.typeArguments}/${ft.typeParameters}', '[String, int]/[E, T]'); |
| 2921 | 2919 |
| 2922 SimpleIdentifier x = findIdentifier('x'); | 2920 SimpleIdentifier x = findIdentifier('x'); |
| 2923 expect(x.staticType, | 2921 expect(x.staticType, |
| 2924 typeProvider.listType.instantiate([typeProvider.intType])); | 2922 typeProvider.listType.instantiate([typeProvider.intType])); |
| 2925 } | 2923 } |
| 2926 | 2924 |
| 2927 test_genericMethod_functionExpressionInvocation_explicit() async { | 2925 test_genericMethod_functionExpressionInvocation_explicit() async { |
| 2928 await resolveTestUnit(r''' | 2926 await resolveTestUnit(r''' |
| 2929 class C<E> { | 2927 class C<E> { |
| 2930 /*=T*/ f/*<T>*/(/*=T*/ e) => null; | 2928 T f<T>(T e) => null; |
| 2931 static /*=T*/ g/*<T>*/(/*=T*/ e) => null; | 2929 static T g<T>(T e) => null; |
| 2932 static final h = g; | 2930 static final h = g; |
| 2933 } | 2931 } |
| 2934 | 2932 |
| 2935 /*=T*/ topF/*<T>*/(/*=T*/ e) => null; | 2933 T topF<T>(T e) => null; |
| 2936 var topG = topF; | 2934 var topG = topF; |
| 2937 void test/*<S>*/(/*=T*/ pf/*<T>*/(/*=T*/ e)) { | 2935 void test<S>(T pf<T>(T e)) { |
| 2938 var c = new C<int>(); | 2936 var c = new C<int>(); |
| 2939 /*=T*/ lf/*<T>*/(/*=T*/ e) => null; | 2937 T lf<T>(T e) => null; |
| 2940 | 2938 |
| 2941 var lambdaCall = (/*<E>*/(/*=E*/ e) => e)/*<int>*/(3); | 2939 var lambdaCall = (<E>(E e) => e)<int>(3); |
| 2942 var methodCall = (c.f)/*<int>*/(3); | 2940 var methodCall = (c.f)<int>(3); |
| 2943 var staticCall = (C.g)/*<int>*/(3); | 2941 var staticCall = (C.g)<int>(3); |
| 2944 var staticFieldCall = (C.h)/*<int>*/(3); | 2942 var staticFieldCall = (C.h)<int>(3); |
| 2945 var topFunCall = (topF)/*<int>*/(3); | 2943 var topFunCall = (topF)<int>(3); |
| 2946 var topFieldCall = (topG)/*<int>*/(3); | 2944 var topFieldCall = (topG)<int>(3); |
| 2947 var localCall = (lf)/*<int>*/(3); | 2945 var localCall = (lf)<int>(3); |
| 2948 var paramCall = (pf)/*<int>*/(3); | 2946 var paramCall = (pf)<int>(3); |
| 2949 } | 2947 } |
| 2950 ''', noErrors: false // TODO(paulberry): remove when dartbug.com/28515 fixed. | 2948 ''', noErrors: false // TODO(paulberry): remove when dartbug.com/28515 fixed. |
| 2951 ); | 2949 ); |
| 2952 expectIdentifierType('methodCall', "int"); | 2950 expectIdentifierType('methodCall', "int"); |
| 2953 expectIdentifierType('staticCall', "int"); | 2951 expectIdentifierType('staticCall', "int"); |
| 2954 expectIdentifierType('staticFieldCall', "int"); | 2952 expectIdentifierType('staticFieldCall', "int"); |
| 2955 expectIdentifierType('topFunCall', "int"); | 2953 expectIdentifierType('topFunCall', "int"); |
| 2956 expectIdentifierType('topFieldCall', "int"); | 2954 expectIdentifierType('topFieldCall', "int"); |
| 2957 expectIdentifierType('localCall', "int"); | 2955 expectIdentifierType('localCall', "int"); |
| 2958 expectIdentifierType('paramCall', "int"); | 2956 expectIdentifierType('paramCall', "int"); |
| 2959 expectIdentifierType('lambdaCall', "int"); | 2957 expectIdentifierType('lambdaCall', "int"); |
| 2960 } | 2958 } |
| 2961 | 2959 |
| 2962 test_genericMethod_functionExpressionInvocation_inferred() async { | 2960 test_genericMethod_functionExpressionInvocation_inferred() async { |
| 2963 await resolveTestUnit(r''' | 2961 await resolveTestUnit(r''' |
| 2964 class C<E> { | 2962 class C<E> { |
| 2965 /*=T*/ f/*<T>*/(/*=T*/ e) => null; | 2963 T f<T>(T e) => null; |
| 2966 static /*=T*/ g/*<T>*/(/*=T*/ e) => null; | 2964 static T g<T>(T e) => null; |
| 2967 static final h = g; | 2965 static final h = g; |
| 2968 } | 2966 } |
| 2969 | 2967 |
| 2970 /*=T*/ topF/*<T>*/(/*=T*/ e) => null; | 2968 T topF<T>(T e) => null; |
| 2971 var topG = topF; | 2969 var topG = topF; |
| 2972 void test/*<S>*/(/*=T*/ pf/*<T>*/(/*=T*/ e)) { | 2970 void test<S>(T pf<T>(T e)) { |
| 2973 var c = new C<int>(); | 2971 var c = new C<int>(); |
| 2974 /*=T*/ lf/*<T>*/(/*=T*/ e) => null; | 2972 T lf<T>(T e) => null; |
| 2975 | 2973 |
| 2976 var lambdaCall = (/*<E>*/(/*=E*/ e) => e)(3); | 2974 var lambdaCall = (<E>(E e) => e)(3); |
| 2977 var methodCall = (c.f)(3); | 2975 var methodCall = (c.f)(3); |
| 2978 var staticCall = (C.g)(3); | 2976 var staticCall = (C.g)(3); |
| 2979 var staticFieldCall = (C.h)(3); | 2977 var staticFieldCall = (C.h)(3); |
| 2980 var topFunCall = (topF)(3); | 2978 var topFunCall = (topF)(3); |
| 2981 var topFieldCall = (topG)(3); | 2979 var topFieldCall = (topG)(3); |
| 2982 var localCall = (lf)(3); | 2980 var localCall = (lf)(3); |
| 2983 var paramCall = (pf)(3); | 2981 var paramCall = (pf)(3); |
| 2984 } | 2982 } |
| 2985 ''', noErrors: false // TODO(paulberry): remove when dartbug.com/28515 fixed. | 2983 ''', noErrors: false // TODO(paulberry): remove when dartbug.com/28515 fixed. |
| 2986 ); | 2984 ); |
| 2987 expectIdentifierType('methodCall', "int"); | 2985 expectIdentifierType('methodCall', "int"); |
| 2988 expectIdentifierType('staticCall', "int"); | 2986 expectIdentifierType('staticCall', "int"); |
| 2989 expectIdentifierType('staticFieldCall', "int"); | 2987 expectIdentifierType('staticFieldCall', "int"); |
| 2990 expectIdentifierType('topFunCall', "int"); | 2988 expectIdentifierType('topFunCall', "int"); |
| 2991 expectIdentifierType('topFieldCall', "int"); | 2989 expectIdentifierType('topFieldCall', "int"); |
| 2992 expectIdentifierType('localCall', "int"); | 2990 expectIdentifierType('localCall', "int"); |
| 2993 expectIdentifierType('paramCall', "int"); | 2991 expectIdentifierType('paramCall', "int"); |
| 2994 expectIdentifierType('lambdaCall', "int"); | 2992 expectIdentifierType('lambdaCall', "int"); |
| 2995 } | 2993 } |
| 2996 | 2994 |
| 2997 test_genericMethod_functionInvocation_explicit() async { | 2995 test_genericMethod_functionInvocation_explicit() async { |
| 2998 await resolveTestUnit(r''' | 2996 await resolveTestUnit(r''' |
| 2999 class C<E> { | 2997 class C<E> { |
| 3000 /*=T*/ f/*<T>*/(/*=T*/ e) => null; | 2998 T f<T>(T e) => null; |
| 3001 static /*=T*/ g/*<T>*/(/*=T*/ e) => null; | 2999 static T g<T>(T e) => null; |
| 3002 static final h = g; | 3000 static final h = g; |
| 3003 } | 3001 } |
| 3004 | 3002 |
| 3005 /*=T*/ topF/*<T>*/(/*=T*/ e) => null; | 3003 T topF<T>(T e) => null; |
| 3006 var topG = topF; | 3004 var topG = topF; |
| 3007 void test/*<S>*/(/*=T*/ pf/*<T>*/(/*=T*/ e)) { | 3005 void test<S>(T pf<T>(T e)) { |
| 3008 var c = new C<int>(); | 3006 var c = new C<int>(); |
| 3009 /*=T*/ lf/*<T>*/(/*=T*/ e) => null; | 3007 T lf<T>(T e) => null; |
| 3010 var methodCall = c.f/*<int>*/(3); | 3008 var methodCall = c.f<int>(3); |
| 3011 var staticCall = C.g/*<int>*/(3); | 3009 var staticCall = C.g<int>(3); |
| 3012 var staticFieldCall = C.h/*<int>*/(3); | 3010 var staticFieldCall = C.h<int>(3); |
| 3013 var topFunCall = topF/*<int>*/(3); | 3011 var topFunCall = topF<int>(3); |
| 3014 var topFieldCall = topG/*<int>*/(3); | 3012 var topFieldCall = topG<int>(3); |
| 3015 var localCall = lf/*<int>*/(3); | 3013 var localCall = lf<int>(3); |
| 3016 var paramCall = pf/*<int>*/(3); | 3014 var paramCall = pf<int>(3); |
| 3017 } | 3015 } |
| 3018 ''', noErrors: false // TODO(paulberry): remove when dartbug.com/28515 fixed. | 3016 ''', noErrors: false // TODO(paulberry): remove when dartbug.com/28515 fixed. |
| 3019 ); | 3017 ); |
| 3020 expectIdentifierType('methodCall', "int"); | 3018 expectIdentifierType('methodCall', "int"); |
| 3021 expectIdentifierType('staticCall', "int"); | 3019 expectIdentifierType('staticCall', "int"); |
| 3022 expectIdentifierType('staticFieldCall', "int"); | 3020 expectIdentifierType('staticFieldCall', "int"); |
| 3023 expectIdentifierType('topFunCall', "int"); | 3021 expectIdentifierType('topFunCall', "int"); |
| 3024 expectIdentifierType('topFieldCall', "int"); | 3022 expectIdentifierType('topFieldCall', "int"); |
| 3025 expectIdentifierType('localCall', "int"); | 3023 expectIdentifierType('localCall', "int"); |
| 3026 expectIdentifierType('paramCall', "int"); | 3024 expectIdentifierType('paramCall', "int"); |
| 3027 } | 3025 } |
| 3028 | 3026 |
| 3029 test_genericMethod_functionInvocation_inferred() async { | 3027 test_genericMethod_functionInvocation_inferred() async { |
| 3030 await resolveTestUnit(r''' | 3028 await resolveTestUnit(r''' |
| 3031 class C<E> { | 3029 class C<E> { |
| 3032 /*=T*/ f/*<T>*/(/*=T*/ e) => null; | 3030 T f<T>(T e) => null; |
| 3033 static /*=T*/ g/*<T>*/(/*=T*/ e) => null; | 3031 static T g<T>(T e) => null; |
| 3034 static final h = g; | 3032 static final h = g; |
| 3035 } | 3033 } |
| 3036 | 3034 |
| 3037 /*=T*/ topF/*<T>*/(/*=T*/ e) => null; | 3035 T topF<T>(T e) => null; |
| 3038 var topG = topF; | 3036 var topG = topF; |
| 3039 void test/*<S>*/(/*=T*/ pf/*<T>*/(/*=T*/ e)) { | 3037 void test<S>(T pf<T>(T e)) { |
| 3040 var c = new C<int>(); | 3038 var c = new C<int>(); |
| 3041 /*=T*/ lf/*<T>*/(/*=T*/ e) => null; | 3039 T lf<T>(T e) => null; |
| 3042 var methodCall = c.f(3); | 3040 var methodCall = c.f(3); |
| 3043 var staticCall = C.g(3); | 3041 var staticCall = C.g(3); |
| 3044 var staticFieldCall = C.h(3); | 3042 var staticFieldCall = C.h(3); |
| 3045 var topFunCall = topF(3); | 3043 var topFunCall = topF(3); |
| 3046 var topFieldCall = topG(3); | 3044 var topFieldCall = topG(3); |
| 3047 var localCall = lf(3); | 3045 var localCall = lf(3); |
| 3048 var paramCall = pf(3); | 3046 var paramCall = pf(3); |
| 3049 } | 3047 } |
| 3050 ''', noErrors: false // TODO(paulberry): remove when dartbug.com/28515 fixed. | 3048 ''', noErrors: false // TODO(paulberry): remove when dartbug.com/28515 fixed. |
| 3051 ); | 3049 ); |
| 3052 expectIdentifierType('methodCall', "int"); | 3050 expectIdentifierType('methodCall', "int"); |
| 3053 expectIdentifierType('staticCall', "int"); | 3051 expectIdentifierType('staticCall', "int"); |
| 3054 expectIdentifierType('staticFieldCall', "int"); | 3052 expectIdentifierType('staticFieldCall', "int"); |
| 3055 expectIdentifierType('topFunCall', "int"); | 3053 expectIdentifierType('topFunCall', "int"); |
| 3056 expectIdentifierType('topFieldCall', "int"); | 3054 expectIdentifierType('topFieldCall', "int"); |
| 3057 expectIdentifierType('localCall', "int"); | 3055 expectIdentifierType('localCall', "int"); |
| 3058 expectIdentifierType('paramCall', "int"); | 3056 expectIdentifierType('paramCall', "int"); |
| 3059 } | 3057 } |
| 3060 | 3058 |
| 3061 test_genericMethod_functionTypedParameter() async { | 3059 test_genericMethod_functionTypedParameter() async { |
| 3062 await resolveTestUnit(r''' | 3060 await resolveTestUnit(r''' |
| 3063 class C<E> { | 3061 class C<E> { |
| 3064 List/*<T>*/ f/*<T>*/(/*=T*/ f(E e)) => null; | 3062 List<T> f<T>(T f(E e)) => null; |
| 3065 } | 3063 } |
| 3066 main() { | 3064 main() { |
| 3067 C<String> cOfString; | 3065 C<String> cOfString; |
| 3068 } | 3066 } |
| 3069 '''); | 3067 '''); |
| 3070 expectFunctionType('f', '<T>((E) → T) → List<T>', | 3068 expectFunctionType('f', '<T>((E) → T) → List<T>', |
| 3071 elementTypeParams: '[T]', | 3069 elementTypeParams: '[T]', |
| 3072 typeParams: '[E]', | 3070 typeParams: '[E]', |
| 3073 typeArgs: '[E]', | 3071 typeArgs: '[E]', |
| 3074 typeFormals: '[T]'); | 3072 typeFormals: '[T]'); |
| 3075 | 3073 |
| 3076 SimpleIdentifier c = findIdentifier('cOfString'); | 3074 SimpleIdentifier c = findIdentifier('cOfString'); |
| 3077 FunctionType ft = (c.staticType as InterfaceType).getMethod('f').type; | 3075 FunctionType ft = (c.staticType as InterfaceType).getMethod('f').type; |
| 3078 expect(ft.toString(), '<T>((String) → T) → List<T>'); | 3076 expect(ft.toString(), '<T>((String) → T) → List<T>'); |
| 3079 ft = ft.instantiate([typeProvider.intType]); | 3077 ft = ft.instantiate([typeProvider.intType]); |
| 3080 expect(ft.toString(), '((String) → int) → List<int>'); | 3078 expect(ft.toString(), '((String) → int) → List<int>'); |
| 3081 } | 3079 } |
| 3082 | 3080 |
| 3083 test_genericMethod_implicitDynamic() async { | 3081 test_genericMethod_implicitDynamic() async { |
| 3084 // Regression test for: | 3082 // Regression test for: |
| 3085 // https://github.com/dart-lang/sdk/issues/25100#issuecomment-162047588 | 3083 // https://github.com/dart-lang/sdk/issues/25100#issuecomment-162047588 |
| 3086 // These should not cause any hints or warnings. | 3084 // These should not cause any hints or warnings. |
| 3087 await resolveTestUnit(r''' | 3085 await resolveTestUnit(r''' |
| 3088 class List<E> { | 3086 class List<E> { |
| 3089 /*=T*/ map/*<T>*/(/*=T*/ f(E e)) => null; | 3087 T map<T>(T f(E e)) => null; |
| 3090 } | 3088 } |
| 3091 void foo() { | 3089 void foo() { |
| 3092 List list = null; | 3090 List list = null; |
| 3093 list.map((e) => e); | 3091 list.map((e) => e); |
| 3094 list.map((e) => 3); | 3092 list.map((e) => 3); |
| 3095 }'''); | 3093 }'''); |
| 3096 expectIdentifierType('map((e) => e);', '<T>((dynamic) → T) → T', isNull); | 3094 expectIdentifierType('map((e) => e);', '<T>((dynamic) → T) → T', isNull); |
| 3097 expectIdentifierType('map((e) => 3);', '<T>((dynamic) → T) → T', isNull); | 3095 expectIdentifierType('map((e) => 3);', '<T>((dynamic) → T) → T', isNull); |
| 3098 | 3096 |
| 3099 MethodInvocation m1 = findIdentifier('map((e) => e);').parent; | 3097 MethodInvocation m1 = findIdentifier('map((e) => e);').parent; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3153 var foo = max(1, 2); | 3151 var foo = max(1, 2); |
| 3154 } | 3152 } |
| 3155 '''; | 3153 '''; |
| 3156 await resolveTestUnit(code); | 3154 await resolveTestUnit(code); |
| 3157 expectInitializerType('foo', 'int', isNull); | 3155 expectInitializerType('foo', 'int', isNull); |
| 3158 } | 3156 } |
| 3159 | 3157 |
| 3160 test_genericMethod_nestedBound() async { | 3158 test_genericMethod_nestedBound() async { |
| 3161 String code = r''' | 3159 String code = r''' |
| 3162 class Foo<T extends num> { | 3160 class Foo<T extends num> { |
| 3163 void method/*<U extends T>*/(dynamic/*=U*/ u) { | 3161 void method<U extends T>(U u) { |
| 3164 u.abs(); | 3162 u.abs(); |
| 3165 } | 3163 } |
| 3166 } | 3164 } |
| 3167 '''; | 3165 '''; |
| 3168 // Just validate that there is no warning on the call to `.abs()`. | 3166 // Just validate that there is no warning on the call to `.abs()`. |
| 3169 await resolveTestUnit(code); | 3167 await resolveTestUnit(code); |
| 3170 } | 3168 } |
| 3171 | 3169 |
| 3172 test_genericMethod_nestedCapture() async { | 3170 test_genericMethod_nestedCapture() async { |
| 3173 await resolveTestUnit(r''' | 3171 await resolveTestUnit(r''' |
| 3174 class C<T> { | 3172 class C<T> { |
| 3175 /*=T*/ f/*<S>*/(/*=S*/ x) { | 3173 T f<S>(S x) { |
| 3176 new C<S>().f/*<int>*/(3); | 3174 new C<S>().f<int>(3); |
| 3177 new C<S>().f; // tear-off | 3175 new C<S>().f; // tear-off |
| 3178 return null; | 3176 return null; |
| 3179 } | 3177 } |
| 3180 } | 3178 } |
| 3181 '''); | 3179 '''); |
| 3182 MethodInvocation f = findIdentifier('f/*<int>*/(3);').parent; | 3180 MethodInvocation f = findIdentifier('f<int>(3);').parent; |
| 3183 expect(f.staticInvokeType.toString(), '(int) → S'); | 3181 expect(f.staticInvokeType.toString(), '(int) → S'); |
| 3184 FunctionType ft = f.staticInvokeType; | 3182 FunctionType ft = f.staticInvokeType; |
| 3185 expect('${ft.typeArguments}/${ft.typeParameters}', '[S, int]/[T, S]'); | 3183 expect('${ft.typeArguments}/${ft.typeParameters}', '[S, int]/[T, S]'); |
| 3186 | 3184 |
| 3187 expectIdentifierType('f;', '<S₀>(S₀) → S'); | 3185 expectIdentifierType('f;', '<S₀>(S₀) → S'); |
| 3188 } | 3186 } |
| 3189 | 3187 |
| 3190 test_genericMethod_nestedFunctions() async { | 3188 test_genericMethod_nestedFunctions() async { |
| 3191 await resolveTestUnit(r''' | 3189 await resolveTestUnit(r''' |
| 3192 /*=S*/ f/*<S>*/(/*=S*/ x) { | 3190 S f<S>(S x) { |
| 3193 g/*<S>*/(/*=S*/ x) => f; | 3191 g<S>(S x) => f; |
| 3194 return null; | 3192 return null; |
| 3195 } | 3193 } |
| 3196 '''); | 3194 '''); |
| 3197 expectIdentifierType('f', '<S>(S) → S'); | 3195 expectIdentifierType('f', '<S>(S) → S'); |
| 3198 expectIdentifierType('g', '<S>(S) → <S>(S) → S'); | 3196 expectIdentifierType('g', '<S>(S) → <S>(S) → S'); |
| 3199 } | 3197 } |
| 3200 | 3198 |
| 3201 test_genericMethod_override() async { | 3199 test_genericMethod_override() async { |
| 3202 await resolveTestUnit(r''' | 3200 await resolveTestUnit(r''' |
| 3203 class C { | 3201 class C { |
| 3204 /*=T*/ f/*<T>*/(/*=T*/ x) => null; | 3202 T f<T>(T x) => null; |
| 3205 } | 3203 } |
| 3206 class D extends C { | 3204 class D extends C { |
| 3207 /*=T*/ f/*<T>*/(/*=T*/ x) => null; // from D | 3205 T f<T>(T x) => null; // from D |
| 3208 } | 3206 } |
| 3209 '''); | 3207 '''); |
| 3210 expectFunctionType('f/*<T>*/(/*=T*/ x) => null; // from D', '<T>(T) → T', | 3208 expectFunctionType('f<T>(T x) => null; // from D', '<T>(T) → T', |
| 3211 elementTypeParams: '[T]', typeFormals: '[T]'); | 3209 elementTypeParams: '[T]', typeFormals: '[T]'); |
| 3212 SimpleIdentifier f = | 3210 SimpleIdentifier f = findIdentifier('f<T>(T x) => null; // from D'); |
| 3213 findIdentifier('f/*<T>*/(/*=T*/ x) => null; // from D'); | |
| 3214 MethodElementImpl e = f.staticElement; | 3211 MethodElementImpl e = f.staticElement; |
| 3215 FunctionType ft = e.type.instantiate([typeProvider.stringType]); | 3212 FunctionType ft = e.type.instantiate([typeProvider.stringType]); |
| 3216 expect(ft.toString(), '(String) → String'); | 3213 expect(ft.toString(), '(String) → String'); |
| 3217 } | 3214 } |
| 3218 | 3215 |
| 3219 test_genericMethod_override_bounds() async { | 3216 test_genericMethod_override_bounds() async { |
| 3220 await resolveTestUnit(r''' | 3217 await resolveTestUnit(r''' |
| 3221 class A {} | 3218 class A {} |
| 3222 class B extends A {} | 3219 class B extends A {} |
| 3223 class C { | 3220 class C { |
| 3224 /*=T*/ f/*<T extends B>*/(/*=T*/ x) => null; | 3221 T f<T extends B>(T x) => null; |
| 3225 } | 3222 } |
| 3226 class D extends C { | 3223 class D extends C { |
| 3227 /*=T*/ f/*<T extends A>*/(/*=T*/ x) => null; | 3224 T f<T extends A>(T x) => null; |
| 3228 } | 3225 } |
| 3229 '''); | 3226 '''); |
| 3230 } | 3227 } |
| 3231 | 3228 |
| 3232 test_genericMethod_override_covariant_field() async { | 3229 test_genericMethod_override_covariant_field() async { |
| 3233 Source source = addSource(r''' | 3230 Source source = addSource(r''' |
| 3234 abstract class A { | 3231 abstract class A { |
| 3235 num get x; | 3232 num get x; |
| 3236 set x(covariant num _); | 3233 set x(covariant num _); |
| 3237 } | 3234 } |
| 3238 | 3235 |
| 3239 class B extends A { | 3236 class B extends A { |
| 3240 int x; | 3237 int x; |
| 3241 } | 3238 } |
| 3242 '''); | 3239 '''); |
| 3243 await computeAnalysisResult(source); | 3240 await computeAnalysisResult(source); |
| 3244 assertNoErrors(source); | 3241 assertNoErrors(source); |
| 3245 verify([source]); | 3242 verify([source]); |
| 3246 } | 3243 } |
| 3247 | 3244 |
| 3248 test_genericMethod_override_invalidReturnType() async { | 3245 test_genericMethod_override_invalidReturnType() async { |
| 3249 Source source = addSource(r''' | 3246 Source source = addSource(r''' |
| 3250 class C { | 3247 class C { |
| 3251 Iterable/*<T>*/ f/*<T>*/(/*=T*/ x) => null; | 3248 Iterable<T> f<T>(T x) => null; |
| 3252 } | 3249 } |
| 3253 class D extends C { | 3250 class D extends C { |
| 3254 String f/*<S>*/(/*=S*/ x) => null; | 3251 String f<S>(S x) => null; |
| 3255 }'''); | 3252 }'''); |
| 3256 await computeAnalysisResult(source); | 3253 await computeAnalysisResult(source); |
| 3257 assertErrors(source, [StrongModeCode.INVALID_METHOD_OVERRIDE]); | 3254 assertErrors(source, [StrongModeCode.INVALID_METHOD_OVERRIDE]); |
| 3258 verify([source]); | 3255 verify([source]); |
| 3259 } | 3256 } |
| 3260 | 3257 |
| 3261 test_genericMethod_override_invalidTypeParamBounds() async { | 3258 test_genericMethod_override_invalidTypeParamBounds() async { |
| 3262 Source source = addSource(r''' | 3259 Source source = addSource(r''' |
| 3263 class A {} | 3260 class A {} |
| 3264 class B extends A {} | 3261 class B extends A {} |
| 3265 class C { | 3262 class C { |
| 3266 /*=T*/ f/*<T extends A>*/(/*=T*/ x) => null; | 3263 T f<T extends A>(T x) => null; |
| 3267 } | 3264 } |
| 3268 class D extends C { | 3265 class D extends C { |
| 3269 /*=T*/ f/*<T extends B>*/(/*=T*/ x) => null; | 3266 T f<T extends B>(T x) => null; |
| 3270 }'''); | 3267 }'''); |
| 3271 await computeAnalysisResult(source); | 3268 await computeAnalysisResult(source); |
| 3272 assertErrors(source, [StrongModeCode.INVALID_METHOD_OVERRIDE]); | 3269 assertErrors(source, [StrongModeCode.INVALID_METHOD_OVERRIDE]); |
| 3273 verify([source]); | 3270 verify([source]); |
| 3274 } | 3271 } |
| 3275 | 3272 |
| 3276 test_genericMethod_override_invalidTypeParamCount() async { | 3273 test_genericMethod_override_invalidTypeParamCount() async { |
| 3277 Source source = addSource(r''' | 3274 Source source = addSource(r''' |
| 3278 class C { | 3275 class C { |
| 3279 /*=T*/ f/*<T>*/(/*=T*/ x) => null; | 3276 T f<T>(T x) => null; |
| 3280 } | 3277 } |
| 3281 class D extends C { | 3278 class D extends C { |
| 3282 /*=S*/ f/*<T, S>*/(/*=T*/ x) => null; | 3279 S f<T, S>(T x) => null; |
| 3283 }'''); | 3280 }'''); |
| 3284 await computeAnalysisResult(source); | 3281 await computeAnalysisResult(source); |
| 3285 assertErrors(source, [StrongModeCode.INVALID_METHOD_OVERRIDE]); | 3282 assertErrors(source, [StrongModeCode.INVALID_METHOD_OVERRIDE]); |
| 3286 verify([source]); | 3283 verify([source]); |
| 3287 } | 3284 } |
| 3288 | 3285 |
| 3289 test_genericMethod_propagatedType_promotion() async { | 3286 test_genericMethod_propagatedType_promotion() async { |
| 3290 // Regression test for: | 3287 // Regression test for: |
| 3291 // https://github.com/dart-lang/sdk/issues/25340 | 3288 // https://github.com/dart-lang/sdk/issues/25340 |
| 3292 | 3289 |
| 3293 // Note, after https://github.com/dart-lang/sdk/issues/25486 the original | 3290 // Note, after https://github.com/dart-lang/sdk/issues/25486 the original |
| 3294 // example won't work, as we now compute a static type and therefore discard | 3291 // example won't work, as we now compute a static type and therefore discard |
| 3295 // the propagated type. So a new test was created that doesn't run under | 3292 // the propagated type. So a new test was created that doesn't run under |
| 3296 // strong mode. | 3293 // strong mode. |
| 3297 await resolveTestUnit(r''' | 3294 await resolveTestUnit(r''' |
| 3298 abstract class Iter { | 3295 abstract class Iter { |
| 3299 List/*<S>*/ map/*<S>*/(/*=S*/ f(x)); | 3296 List<S> map<S>(S f(x)); |
| 3300 } | 3297 } |
| 3301 class C {} | 3298 class C {} |
| 3302 C toSpan(dynamic element) { | 3299 C toSpan(dynamic element) { |
| 3303 if (element is Iter) { | 3300 if (element is Iter) { |
| 3304 var y = element.map(toSpan); | 3301 var y = element.map(toSpan); |
| 3305 } | 3302 } |
| 3306 return null; | 3303 return null; |
| 3307 }'''); | 3304 }'''); |
| 3308 expectIdentifierType('y = ', 'List<C>', isNull); | 3305 expectIdentifierType('y = ', 'List<C>', isNull); |
| 3309 } | 3306 } |
| 3310 | 3307 |
| 3311 test_genericMethod_tearoff() async { | 3308 test_genericMethod_tearoff() async { |
| 3312 await resolveTestUnit(r''' | 3309 await resolveTestUnit(r''' |
| 3313 class C<E> { | 3310 class C<E> { |
| 3314 /*=T*/ f/*<T>*/(E e) => null; | 3311 T f<T>(E e) => null; |
| 3315 static /*=T*/ g/*<T>*/(/*=T*/ e) => null; | 3312 static T g<T>(T e) => null; |
| 3316 static final h = g; | 3313 static final h = g; |
| 3317 } | 3314 } |
| 3318 | 3315 |
| 3319 /*=T*/ topF/*<T>*/(/*=T*/ e) => null; | 3316 T topF<T>(T e) => null; |
| 3320 var topG = topF; | 3317 var topG = topF; |
| 3321 void test/*<S>*/(/*=T*/ pf/*<T>*/(/*=T*/ e)) { | 3318 void test<S>(T pf<T>(T e)) { |
| 3322 var c = new C<int>(); | 3319 var c = new C<int>(); |
| 3323 /*=T*/ lf/*<T>*/(/*=T*/ e) => null; | 3320 T lf<T>(T e) => null; |
| 3324 var methodTearOff = c.f; | 3321 var methodTearOff = c.f; |
| 3325 var staticTearOff = C.g; | 3322 var staticTearOff = C.g; |
| 3326 var staticFieldTearOff = C.h; | 3323 var staticFieldTearOff = C.h; |
| 3327 var topFunTearOff = topF; | 3324 var topFunTearOff = topF; |
| 3328 var topFieldTearOff = topG; | 3325 var topFieldTearOff = topG; |
| 3329 var localTearOff = lf; | 3326 var localTearOff = lf; |
| 3330 var paramTearOff = pf; | 3327 var paramTearOff = pf; |
| 3331 } | 3328 } |
| 3332 ''', noErrors: false // TODO(paulberry): remove when dartbug.com/28515 fixed. | 3329 ''', noErrors: false // TODO(paulberry): remove when dartbug.com/28515 fixed. |
| 3333 ); | 3330 ); |
| (...skipping 844 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4178 var v = x; | 4175 var v = x; |
| 4179 v; // marker | 4176 v; // marker |
| 4180 } | 4177 } |
| 4181 int x = 3; | 4178 int x = 3; |
| 4182 '''; | 4179 '''; |
| 4183 CompilationUnit unit = await resolveSource(code); | 4180 CompilationUnit unit = await resolveSource(code); |
| 4184 assertPropagatedAssignedType(code, unit, typeProvider.intType, null); | 4181 assertPropagatedAssignedType(code, unit, typeProvider.intType, null); |
| 4185 assertTypeOfMarkedExpression(code, unit, typeProvider.intType, null); | 4182 assertTypeOfMarkedExpression(code, unit, typeProvider.intType, null); |
| 4186 } | 4183 } |
| 4187 } | 4184 } |
| OLD | NEW |