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

Side by Side Diff: pkg/analyzer/test/src/task/strong/checker_test.dart

Issue 1678313002: fix part of #25200, reject non-generic function subtype of generic function (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: fix synthetic ctor Created 4 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) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 // TODO(jmesserly): this file needs to be refactored, it's a port from 5 // TODO(jmesserly): this file needs to be refactored, it's a port from
6 // package:dev_compiler's tests 6 // package:dev_compiler's tests
7 /// General type checking tests 7 /// General type checking tests
8 library analyzer.test.src.task.strong.checker_test; 8 library analyzer.test.src.task.strong.checker_test;
9 9
10 import 'package:unittest/unittest.dart'; 10 import 'package:unittest/unittest.dart';
(...skipping 1143 matching lines...) Expand 10 before | Expand all | Expand 10 after
1154 1154
1155 class A { 1155 class A {
1156 void bar() => null; 1156 void bar() => null;
1157 void foo() => bar; // allowed 1157 void foo() => bar; // allowed
1158 } 1158 }
1159 '''); 1159 ''');
1160 }); 1160 });
1161 1161
1162 test('uninferred closure', () { 1162 test('uninferred closure', () {
1163 checkFile(''' 1163 checkFile('''
1164 typedef num Num2Num(num x); 1164 typedef num Num2Num(num x);
1165 void main() { 1165 void main() {
1166 Num2Num g = /*info:INFERRED_TYPE_CLOSURE,severe:STATIC_TYPE_ERROR*/(int x) { return x; }; 1166 Num2Num g = /*info:INFERRED_TYPE_CLOSURE,severe:STATIC_TYPE_ERROR*/(in t x) { return x; };
1167 print(g(42)); 1167 print(g(42));
1168 } 1168 }
1169 '''); 1169 ''');
1170 });
1171
1172 test('subtype of universal type', () {
1173 checkFile('''
1174 void main() {
1175 nonGenericFn(x) => null;
1176 {
1177 /*=R*/ f/*<P, R>*/(/*=P*/ p) => null;
1178 /*=T*/ g/*<S, T>*/(/*=S*/ s) => null;
1179
1180 var local = f;
1181 local = g; // valid
1182
1183 // Non-generic function cannot subtype a generic one.
1184 local = /*severe:STATIC_TYPE_ERROR*/(x) => null;
1185 local = /*severe:STATIC_TYPE_ERROR*/nonGenericFn;
1186 }
1187 {
1188 Iterable/*<R>*/ f/*<P, R>*/(List/*<P>*/ p) => null;
1189 List/*<T>*/ g/*<S, T>*/(Iterable/*<S>*/ s) => null;
1190
1191 var local = f;
1192 local = g; // valid
1193
1194 var local2 = g;
1195 local = local2;
1196 local2 = /*severe:STATIC_TYPE_ERROR*/f;
1197 local2 = /*warning:DOWN_CAST_COMPOSITE*/local;
1198
1199 // Non-generic function cannot subtype a generic one.
1200 local = /*severe:STATIC_TYPE_ERROR*/(x) => null;
1201 local = /*severe:STATIC_TYPE_ERROR*/nonGenericFn;
1202 }
1203 }
1204 ''');
1170 }); 1205 });
1171 }); 1206 });
1172 1207
1173 test('Relaxed casts', () { 1208 test('Relaxed casts', () {
1174 checkFile(''' 1209 checkFile('''
1175 1210
1176 class A {} 1211 class A {}
1177 1212
1178 class L<T> {} 1213 class L<T> {}
1179 class M<T> extends L<T> {} 1214 class M<T> extends L<T> {}
(...skipping 1410 matching lines...) Expand 10 before | Expand all | Expand 10 after
2590 } 2625 }
2591 2626
2592 class M2 { 2627 class M2 {
2593 m(B a) {} 2628 m(B a) {}
2594 } 2629 }
2595 2630
2596 // Here we want to report both, because the error location is 2631 // Here we want to report both, because the error location is
2597 // different. 2632 // different.
2598 // TODO(sigmund): should we merge these as well? 2633 // TODO(sigmund): should we merge these as well?
2599 class T1 extends Object 2634 class T1 extends Object
2600 with /*severe:INVALID_METHOD_OVERRIDE*/M1 2635 with /*severe:INVALID_METHOD_OVERRIDE*/M1,
2601 with /*severe:INVALID_METHOD_OVERRIDE*/M2 2636 /*severe:INVALID_METHOD_OVERRIDE*/M2
2602 implements I1 { 2637 implements I1 {
2603 } 2638 }
2604 '''); 2639 ''');
2605 }); 2640 });
2606 2641
2607 test('base type and mixin override same method in interface', () { 2642 test('base type and mixin override same method in interface', () {
2608 checkFile(''' 2643 checkFile('''
2609 class A {} 2644 class A {}
2610 class B {} 2645 class B {}
2611 2646
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
2759 2794
2760 baz1() sync* { yield* (/*info:DYNAMIC_CAST*/x); } 2795 baz1() sync* { yield* (/*info:DYNAMIC_CAST*/x); }
2761 Iterable baz2() sync* { yield* (/*info:DYNAMIC_CAST*/x); } 2796 Iterable baz2() sync* { yield* (/*info:DYNAMIC_CAST*/x); }
2762 Iterable<int> baz3() sync* { yield* (/*warning:DOWN_CAST_COMPOSITE*/x); } 2797 Iterable<int> baz3() sync* { yield* (/*warning:DOWN_CAST_COMPOSITE*/x); }
2763 Iterable<int> baz4() sync* { yield* new Iterable<int>(); } 2798 Iterable<int> baz4() sync* { yield* new Iterable<int>(); }
2764 Iterable<int> baz5() sync* { yield* (/*info:INFERRED_TYPE_ALLOCATION*/ne w Iterable()); } 2799 Iterable<int> baz5() sync* { yield* (/*info:INFERRED_TYPE_ALLOCATION*/ne w Iterable()); }
2765 '''); 2800 ''');
2766 }); 2801 });
2767 }); 2802 });
2768 } 2803 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/type_system.dart ('k') | pkg/analyzer/test/src/task/strong/inferred_type_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698