Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(137)

Side by Side Diff: pkg/analyzer/test/generated/strong_mode_test.dart

Issue 2658303002: Relax type bound restrictions slightly, apply to typedefs. (Closed)
Patch Set: Typing fix Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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; 5 library analyzer.test.generated.strong_mode_test;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analyzer/dart/ast/ast.dart'; 9 import 'package:analyzer/dart/ast/ast.dart';
10 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; 10 import 'package:analyzer/dart/ast/standard_resolution_map.dart';
(...skipping 2751 matching lines...) Expand 10 before | Expand all | Expand 10 after
2762 await resolveTestUnit(code); 2762 await resolveTestUnit(code);
2763 expectInitializerType('foo', 'Future<String>', isNull); 2763 expectInitializerType('foo', 'Future<String>', isNull);
2764 } 2764 }
2765 2765
2766 test_implicitBounds() async { 2766 test_implicitBounds() async {
2767 String code = r''' 2767 String code = r'''
2768 class A<T> {} 2768 class A<T> {}
2769 2769
2770 class B<T extends num> {} 2770 class B<T extends num> {}
2771 2771
2772 class C<S extends int, T extends B<S>, U extends B> {} 2772 class C<S extends int, T extends B<S>, U extends A> {}
2773 2773
2774 void test() { 2774 void test() {
2775 // 2775 //
2776 A ai; 2776 A ai;
2777 B bi; 2777 B bi;
2778 C ci; 2778 C ci;
2779 var aa = new A(); 2779 var aa = new A();
2780 var bb = new B(); 2780 var bb = new B();
2781 var cc = new C(); 2781 var cc = new C();
2782 } 2782 }
2783 '''; 2783 ''';
2784 await resolveTestUnit(code, noErrors: false); 2784 await resolveTestUnit(code);
2785 expectIdentifierType('ai', "A<dynamic>"); 2785 expectIdentifierType('ai', "A<dynamic>");
2786 expectIdentifierType('bi', "B<num>"); 2786 expectIdentifierType('bi', "B<num>");
2787 expectIdentifierType('ci', "C<int, B<int>, B<dynamic>>"); 2787 expectIdentifierType('ci', "C<int, B<int>, A<dynamic>>");
2788 expectIdentifierType('aa', "A<dynamic>"); 2788 expectIdentifierType('aa', "A<dynamic>");
2789 expectIdentifierType('bb', "B<num>"); 2789 expectIdentifierType('bb', "B<num>");
2790 expectIdentifierType('cc', "C<int, B<int>, B<dynamic>>"); 2790 expectIdentifierType('cc', "C<int, B<int>, A<dynamic>>");
2791 } 2791 }
2792 2792
2793 test_instantiateToBounds_class_error_recursion() async { 2793 test_instantiateToBounds_class_error_recursion() async {
2794 String code = r''' 2794 String code = r'''
2795 class C<T0 extends List<T1>, T1 extends List<T0>> {} 2795 class C<T0 extends List<T1>, T1 extends List<T0>> {}
2796 C c; 2796 C c;
2797 '''; 2797 ''';
2798 await resolveTestUnit(code, noErrors: false); 2798 await resolveTestUnit(code, noErrors: false);
2799 assertErrors(testSource, [StrongModeCode.NO_DEFAULT_BOUNDS]); 2799 assertErrors(testSource, [StrongModeCode.NO_DEFAULT_BOUNDS]);
2800 expectIdentifierType('c;', 'C<dynamic, dynamic>'); 2800 expectIdentifierType('c;', 'C<dynamic, dynamic>');
(...skipping 13 matching lines...) Expand all
2814 String code = r''' 2814 String code = r'''
2815 class A<E> {} 2815 class A<E> {}
2816 class C<T extends A<T>> {} 2816 class C<T extends A<T>> {}
2817 C c; 2817 C c;
2818 '''; 2818 ''';
2819 await resolveTestUnit(code, noErrors: false); 2819 await resolveTestUnit(code, noErrors: false);
2820 assertErrors(testSource, [StrongModeCode.NO_DEFAULT_BOUNDS]); 2820 assertErrors(testSource, [StrongModeCode.NO_DEFAULT_BOUNDS]);
2821 expectIdentifierType('c;', 'C<dynamic>'); 2821 expectIdentifierType('c;', 'C<dynamic>');
2822 } 2822 }
2823 2823
2824 test_instantiateToBounds_class_error_typedef() async {
2825 String code = r'''
2826 typedef T F<T>(T x);
2827 class C<T extends F<T>> {}
2828 C c;
2829 ''';
2830 await resolveTestUnit(code, noErrors: false);
2831 assertErrors(testSource, [StrongModeCode.NO_DEFAULT_BOUNDS]);
2832 expectIdentifierType('c;', 'C<dynamic>');
2833 }
2834
2835 test_instantiateToBounds_class_ok_implicitDynamic_multi() async {
2836 String code = r'''
2837 class C<T0 extends Map<T1, T2>, T1 extends List, T2 extends int> {}
2838 C c;
2839 ''';
2840 await resolveTestUnit(code);
2841 assertNoErrors(testSource);
2842 expectIdentifierType(
2843 'c;', 'C<Map<List<dynamic>, int>, List<dynamic>, int>');
2844 }
2845
2824 test_instantiateToBounds_class_ok_referenceOther_after() async { 2846 test_instantiateToBounds_class_ok_referenceOther_after() async {
2825 String code = r''' 2847 String code = r'''
2826 class C<T0 extends T1, T1 extends int> {} 2848 class C<T0 extends T1, T1 extends int> {}
2827 C c; 2849 C c;
2828 '''; 2850 ''';
2829 await resolveTestUnit(code); 2851 await resolveTestUnit(code);
2830 assertNoErrors(testSource); 2852 assertNoErrors(testSource);
2831 expectIdentifierType('c;', 'C<int, int>'); 2853 expectIdentifierType('c;', 'C<int, int>');
2832 } 2854 }
2833 2855
(...skipping 25 matching lines...) Expand all
2859 await resolveTestUnit(code); 2881 await resolveTestUnit(code);
2860 assertNoErrors(testSource); 2882 assertNoErrors(testSource);
2861 expectIdentifierType('c;', 'C<Map<List<int>, int>, List<int>, int>'); 2883 expectIdentifierType('c;', 'C<Map<List<int>, int>, List<int>, int>');
2862 } 2884 }
2863 2885
2864 test_instantiateToBounds_class_ok_simpleBounds() async { 2886 test_instantiateToBounds_class_ok_simpleBounds() async {
2865 String code = r''' 2887 String code = r'''
2866 class A<T> {} 2888 class A<T> {}
2867 class B<T extends num> {} 2889 class B<T extends num> {}
2868 class C<T extends List<int>> {} 2890 class C<T extends List<int>> {}
2869 2891 class D<T extends A> {}
2870 void main() { 2892 void main() {
2871 A a; 2893 A a;
2872 B b; 2894 B b;
2873 C c; 2895 C c;
2896 D d;
2874 } 2897 }
2875 '''; 2898 ''';
2876 await resolveTestUnit(code); 2899 await resolveTestUnit(code);
2877 assertNoErrors(testSource); 2900 assertNoErrors(testSource);
2878 expectIdentifierType('a;', 'A<dynamic>'); 2901 expectIdentifierType('a;', 'A<dynamic>');
2879 expectIdentifierType('b;', 'B<num>'); 2902 expectIdentifierType('b;', 'B<num>');
2880 expectIdentifierType('c;', 'C<List<int>>'); 2903 expectIdentifierType('c;', 'C<List<int>>');
2904 expectIdentifierType('d;', 'D<A<dynamic>>');
2881 } 2905 }
2882 2906
2883 test_instantiateToBounds_method_ok_referenceOther_before() async { 2907 test_instantiateToBounds_method_ok_referenceOther_before() async {
2884 String code = r''' 2908 String code = r'''
2885 class C<T> { 2909 class C<T> {
2886 void m<S0 extends T, S1 extends List<S0>>(S0 p0, S1 p1) {} 2910 void m<S0 extends T, S1 extends List<S0>>(S0 p0, S1 p1) {}
2887 2911
2888 void main() { 2912 void main() {
2889 m(null, null); 2913 m(null, null);
2890 } 2914 }
(...skipping 12 matching lines...) Expand all
2903 void main() { 2927 void main() {
2904 m(null); 2928 m(null);
2905 } 2929 }
2906 } 2930 }
2907 '''; 2931 ''';
2908 await resolveTestUnit(code); 2932 await resolveTestUnit(code);
2909 assertNoErrors(testSource); 2933 assertNoErrors(testSource);
2910 expectStaticInvokeType('m(null)', '(T) → void'); 2934 expectStaticInvokeType('m(null)', '(T) → void');
2911 } 2935 }
2912 2936
2913 test_notInstantiatedBound_direct() async { 2937 test_notInstantiatedBound_direct_class_class() async {
2914 String code = r''' 2938 String code = r'''
2915 class A<T> {} 2939 class A<T extends int> {}
2916 class C<T extends A> {} 2940 class C<T extends A> {}
2917 '''; 2941 ''';
2918 await resolveTestUnit(code, noErrors: false); 2942 await resolveTestUnit(code, noErrors: false);
2919 assertErrors(testSource, [StrongModeCode.NOT_INSTANTIATED_BOUND]); 2943 assertErrors(testSource, [StrongModeCode.NOT_INSTANTIATED_BOUND]);
2920 } 2944 }
2921 2945
2922 test_notInstantiatedBound_indirect() async { 2946 test_notInstantiatedBound_direct_class_typedef() async {
2947 // Check that if the bound of a class is an uninstantiated typedef
2948 // we emit an error
2949 String code = r'''
2950 typedef void F<T extends int>();
2951 class C<T extends F> {}
2952 ''';
2953 await resolveTestUnit(code, noErrors: false);
2954 assertErrors(testSource, [StrongModeCode.NOT_INSTANTIATED_BOUND]);
2955 }
2956
2957 test_notInstantiatedBound_direct_typedef_class() async {
2958 // Check that if the bound of a typeded is an uninstantiated class
2959 // we emit an error
2960 String code = r'''
2961 class C<T extends int> {}
2962 typedef void F<T extends C>();
2963 ''';
2964 await resolveTestUnit(code, noErrors: false);
2965 assertErrors(testSource, [StrongModeCode.NOT_INSTANTIATED_BOUND]);
2966 }
2967
2968 test_notInstantiatedBound_indirect_class_class() async {
2923 String code = r''' 2969 String code = r'''
2924 class A<T> {} 2970 class A<T> {}
2925 class B<T> {} 2971 class B<T extends int> {}
2926 class C<T extends A<B>> {} 2972 class C<T extends A<B>> {}
2927 '''; 2973 ''';
2928 await resolveTestUnit(code, noErrors: false); 2974 await resolveTestUnit(code, noErrors: false);
2929 assertErrors(testSource, [StrongModeCode.NOT_INSTANTIATED_BOUND]); 2975 assertErrors(testSource, [StrongModeCode.NOT_INSTANTIATED_BOUND]);
2930 } 2976 }
2931 2977
2932 test_notInstantiatedBound_indirect2() async { 2978 test_notInstantiatedBound_indirect_class_class2() async {
2933 String code = r''' 2979 String code = r'''
2934 class A<K, V> {} 2980 class A<K, V> {}
2935 class B<T> {} 2981 class B<T extends int> {}
2936 class C<T extends A<B, B>> {} 2982 class C<T extends A<B, B>> {}
2937 '''; 2983 ''';
2938 await resolveTestUnit(code, noErrors: false); 2984 await resolveTestUnit(code, noErrors: false);
2939 assertErrors(testSource, [ 2985 assertErrors(testSource, [
2940 StrongModeCode.NOT_INSTANTIATED_BOUND, 2986 StrongModeCode.NOT_INSTANTIATED_BOUND,
2941 StrongModeCode.NOT_INSTANTIATED_BOUND 2987 StrongModeCode.NOT_INSTANTIATED_BOUND
2942 ]); 2988 ]);
2943 } 2989 }
2944 2990
2945 test_objectMethodOnFunctions_Anonymous() async { 2991 test_objectMethodOnFunctions_Anonymous() async {
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after
3414 var v = x; 3460 var v = x;
3415 v; // marker 3461 v; // marker
3416 } 3462 }
3417 int x = 3; 3463 int x = 3;
3418 '''; 3464 ''';
3419 CompilationUnit unit = await resolveSource(code); 3465 CompilationUnit unit = await resolveSource(code);
3420 assertPropagatedAssignedType(code, unit, typeProvider.intType, null); 3466 assertPropagatedAssignedType(code, unit, typeProvider.intType, null);
3421 assertTypeOfMarkedExpression(code, unit, typeProvider.intType, null); 3467 assertTypeOfMarkedExpression(code, unit, typeProvider.intType, null);
3422 } 3468 }
3423 } 3469 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698