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

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

Issue 1921823007: Make types concrete when checking overrides. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 7 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 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 await for (var s in new Stream<String>()) {} 222 await for (var s in new Stream<String>()) {}
223 223
224 // Downcast. 224 // Downcast.
225 await for (int /*info:DOWN_CAST_IMPLICIT*/i in new Stream<num>()) {} 225 await for (int /*info:DOWN_CAST_IMPLICIT*/i in new Stream<num>()) {}
226 } 226 }
227 '''); 227 ''');
228 }); 228 });
229 229
230 test('dynamic invocation', () { 230 test('dynamic invocation', () {
231 checkFile(''' 231 checkFile('''
232 class A { 232 typedef dynamic A(dynamic x);
233 dynamic call(dynamic x) => x; 233 class B {
234 }
235 class B extends A {
236 int call(int x) => x; 234 int call(int x) => x;
237 double col(double x) => x; 235 double col(double x) => x;
238 } 236 }
239 void main() { 237 void main() {
240 { 238 {
241 B f = new B(); 239 B f = new B();
242 int x; 240 int x;
243 double y; 241 double y;
244 x = f(3); 242 x = f(3);
245 x = /*warning:INVALID_ASSIGNMENT*/f.col(3.0); 243 x = /*warning:INVALID_ASSIGNMENT*/f.col(3.0);
(...skipping 23 matching lines...) Expand all
269 y = /*info:DYNAMIC_CAST, info:DYNAMIC_INVOKE*/f(3); 267 y = /*info:DYNAMIC_CAST, info:DYNAMIC_INVOKE*/f(3);
270 /*info:DYNAMIC_INVOKE*/f(3.0); 268 /*info:DYNAMIC_INVOKE*/f(3.0);
271 } 269 }
272 { 270 {
273 dynamic g = new B(); 271 dynamic g = new B();
274 /*info:DYNAMIC_INVOKE*/g.call(/*info:ARGUMENT_TYPE_NOT_ASSIGNABLE*/32. 0); 272 /*info:DYNAMIC_INVOKE*/g.call(/*info:ARGUMENT_TYPE_NOT_ASSIGNABLE*/32. 0);
275 /*info:DYNAMIC_INVOKE*/g.col(42.0); 273 /*info:DYNAMIC_INVOKE*/g.col(42.0);
276 /*info:DYNAMIC_INVOKE*/g.foo(42.0); 274 /*info:DYNAMIC_INVOKE*/g.foo(42.0);
277 /*info:DYNAMIC_INVOKE*/g./*info:UNDEFINED_GETTER*/x; 275 /*info:DYNAMIC_INVOKE*/g./*info:UNDEFINED_GETTER*/x;
278 A f = new B(); 276 A f = new B();
279 f.call(/*info:ARGUMENT_TYPE_NOT_ASSIGNABLE*/32.0);
280 /*info:DYNAMIC_INVOKE*/f.col(42.0); 277 /*info:DYNAMIC_INVOKE*/f.col(42.0);
281 /*info:DYNAMIC_INVOKE*/f.foo(42.0); 278 /*info:DYNAMIC_INVOKE*/f.foo(42.0);
282 /*info:DYNAMIC_INVOKE*/f./*warning:UNDEFINED_GETTER*/x; 279 /*info:DYNAMIC_INVOKE*/f./*warning:UNDEFINED_GETTER*/x;
283 } 280 }
284 } 281 }
285 '''); 282 ''');
286 }); 283 });
287 284
288 test('conversion and dynamic invoke', () { 285 test('conversion and dynamic invoke', () {
289 addFile( 286 addFile(
(...skipping 1705 matching lines...) Expand 10 before | Expand all | Expand 10 after
1995 /*severe:INVALID_METHOD_OVERRIDE*/A m1(A value) => null; 1992 /*severe:INVALID_METHOD_OVERRIDE*/A m1(A value) => null;
1996 /*severe:INVALID_METHOD_OVERRIDE*/C m2(C value) => null; 1993 /*severe:INVALID_METHOD_OVERRIDE*/C m2(C value) => null;
1997 /*severe:INVALID_METHOD_OVERRIDE*/A m3(C value) => null; 1994 /*severe:INVALID_METHOD_OVERRIDE*/A m3(C value) => null;
1998 C m4(A value) => null; 1995 C m4(A value) => null;
1999 m5(value) => null; 1996 m5(value) => null;
2000 /*severe:INVALID_METHOD_OVERRIDE*/dynamic m6(dynamic value) => null; 1997 /*severe:INVALID_METHOD_OVERRIDE*/dynamic m6(dynamic value) => null;
2001 } 1998 }
2002 '''); 1999 ''');
2003 }); 2000 });
2004 2001
2002 test('method override, fuzzy arrows', () {
2003 checkFile('''
2004 abstract class A {
2005 bool operator ==(Object object);
2006 }
2007
2008 class B implements A {}
2009
2010
2011 class F {
2012 void f(x) {}
2013 void g(int x) {}
2014 }
2015
2016 class G extends F {
2017 /*severe:INVALID_METHOD_OVERRIDE*/void f(int x) {}
2018 void g(dynamic x) {}
2019 }
2020
2021 class H implements F {
2022 /*severe:INVALID_METHOD_OVERRIDE*/void f(int x) {}
2023 void g(dynamic x) {}
2024 }
2025
2026 ''');
2027 });
2028
2029 test('getter override, fuzzy arrows', () {
2030 checkFile('''
2031 typedef void ToVoid<T>(T x);
2032 class F {
2033 ToVoid<dynamic> get f => null;
2034 ToVoid<int> get g => null;
2035 }
2036
2037 class G extends F {
2038 ToVoid<int> get f => null;
2039 /*severe:INVALID_METHOD_OVERRIDE*/ToVoid<dynamic> get g => null;
2040 }
2041
2042 class H implements F {
2043 ToVoid<int> get f => null;
2044 /*severe:INVALID_METHOD_OVERRIDE*/ToVoid<dynamic> get g => null;
2045 }
2046 ''');
2047 });
2048
2049 test('setter override, fuzzy arrows', () {
2050 checkFile('''
2051 typedef void ToVoid<T>(T x);
2052 class F {
2053 void set f(ToVoid<dynamic> x) {}
2054 void set g(ToVoid<int> x) {}
2055 void set h(dynamic x) {}
2056 void set i(int x) {}
2057 }
2058
2059 class G extends F {
2060 /*severe:INVALID_METHOD_OVERRIDE*/void set f(ToVoid<int> x) {}
2061 void set g(ToVoid<dynamic> x) {}
2062 void set h(int x) {}
2063 /*severe:INVALID_METHOD_OVERRIDE*/void set i(dynamic x) {}
2064 }
2065
2066 class H implements F {
2067 /*severe:INVALID_METHOD_OVERRIDE*/void set f(ToVoid<int> x) {}
2068 void set g(ToVoid<dynamic> x) {}
2069 void set h(int x) {}
2070 /*severe:INVALID_METHOD_OVERRIDE*/void set i(dynamic x) {}
2071 }
2072 ''');
2073 });
2074
2075 test('field override, fuzzy arrows', () {
2076 checkFile('''
2077 typedef void ToVoid<T>(T x);
2078 class F {
2079 final ToVoid<dynamic> f = null;
2080 final ToVoid<int> g = null;
2081 }
2082
2083 class G extends F {
2084 /*severe:INVALID_FIELD_OVERRIDE*/final ToVoid<int> f = null;
2085 /*severe:INVALID_FIELD_OVERRIDE, severe:INVALID_METHOD_OVERRIDE*/final T oVoid<dynamic> g = null;
2086 }
2087
2088 class H implements F {
2089 final ToVoid<int> f = null;
2090 /*severe:INVALID_METHOD_OVERRIDE*/final ToVoid<dynamic> g = null;
2091 }
2092 ''');
2093 });
2094
2005 test('generic class method override', () { 2095 test('generic class method override', () {
2006 checkFile(''' 2096 checkFile('''
2007 class A {} 2097 class A {}
2008 class B extends A {} 2098 class B extends A {}
2009 2099
2010 class Base<T extends B> { 2100 class Base<T extends B> {
2011 T foo() => null; 2101 T foo() => null;
2012 } 2102 }
2013 2103
2014 class Derived<S extends A> extends Base<B> { 2104 class Derived<S extends A> extends Base<B> {
(...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after
2624 2714
2625 class I1 { 2715 class I1 {
2626 m(B a) {} 2716 m(B a) {}
2627 } 2717 }
2628 2718
2629 class /*warning:INCONSISTENT_METHOD_INHERITANCE*/T1 2719 class /*warning:INCONSISTENT_METHOD_INHERITANCE*/T1
2630 /*severe:INVALID_METHOD_OVERRIDE*/extends Base 2720 /*severe:INVALID_METHOD_OVERRIDE*/extends Base
2631 implements I1 {} 2721 implements I1 {}
2632 2722
2633 class T2 extends Base implements I1 { 2723 class T2 extends Base implements I1 {
2634 /*severe:INVALID_METHOD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE* /m(a) {} 2724 m(a) {}
2635 } 2725 }
2636 2726
2637 class /*warning:INCONSISTENT_METHOD_INHERITANCE*/T3 2727 class /*warning:INCONSISTENT_METHOD_INHERITANCE*/T3
2638 extends Object with /*severe:INVALID_METHOD_OVERRIDE*/Base 2728 extends Object with /*severe:INVALID_METHOD_OVERRIDE*/Base
2639 implements I1 {} 2729 implements I1 {}
2640 2730
2641 class T4 extends Object with Base implements I1 { 2731 class T4 extends Object with Base implements I1 {
2642 /*severe:INVALID_METHOD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE* /m(a) {} 2732 m(a) {}
2643 } 2733 }
2644 '''); 2734 ''');
2645 }); 2735 });
2646 }); 2736 });
2647 2737
2648 group('class override of grand interface', () { 2738 group('class override of grand interface', () {
2649 test('interface of interface of child', () { 2739 test('interface of interface of child', () {
2650 checkFile(''' 2740 checkFile('''
2651 class A {} 2741 class A {}
2652 class B {} 2742 class B {}
(...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after
3217 3307
3218 baz1() sync* { yield* /*info:DYNAMIC_CAST*/x; } 3308 baz1() sync* { yield* /*info:DYNAMIC_CAST*/x; }
3219 Iterable baz2() sync* { yield* /*info:DYNAMIC_CAST*/x; } 3309 Iterable baz2() sync* { yield* /*info:DYNAMIC_CAST*/x; }
3220 Iterable<int> baz3() sync* { yield* /*warning:DOWN_CAST_COMPOSITE*/x; } 3310 Iterable<int> baz3() sync* { yield* /*warning:DOWN_CAST_COMPOSITE*/x; }
3221 Iterable<int> baz4() sync* { yield* bar3(); } 3311 Iterable<int> baz4() sync* { yield* bar3(); }
3222 Iterable<int> baz5() sync* { yield* /*info:INFERRED_TYPE_ALLOCATION*/new List(); } 3312 Iterable<int> baz5() sync* { yield* /*info:INFERRED_TYPE_ALLOCATION*/new List(); }
3223 '''); 3313 ''');
3224 }); 3314 });
3225 }); 3315 });
3226 } 3316 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/task/strong/checker.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