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

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

Issue 1843453002: Better strong mode least upper bound for interface types. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Merge hell Created 4 years, 8 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 int i = 42; 55 int i = 42;
56 56
57 // Check the boolean conversion of the condition. 57 // Check the boolean conversion of the condition.
58 print(/*warning:NON_BOOL_CONDITION*/i ? false : true); 58 print(/*warning:NON_BOOL_CONDITION*/i ? false : true);
59 print((/*info:DOWN_CAST_IMPLICIT*/obj) ? false : true); 59 print((/*info:DOWN_CAST_IMPLICIT*/obj) ? false : true);
60 print((/*info:DYNAMIC_CAST*/dyn) ? false : true); 60 print((/*info:DYNAMIC_CAST*/dyn) ? false : true);
61 } 61 }
62 '''); 62 ''');
63 }); 63 });
64 64
65 test('least upper bounds', () {
66 checkFile('''
67 typedef T Returns<T>();
68
69 // regression test for https://github.com/dart-lang/sdk/issues/26094
70 class A <S extends Returns<S>, T extends Returns<T>> {
71 int test(bool b) {
72 S s;
73 T t;
74 if (b) {
75 return /*warning:RETURN_OF_INVALID_TYPE*/b ? s : t;
76 } else {
77 return /*warning:RETURN_OF_INVALID_TYPE*/s ?? t;
78 }
79 }
80 }
81
82 class B<S, T extends S> {
83 T t;
84 S s;
85 int test(bool b) {
86 return /*warning:RETURN_OF_INVALID_TYPE*/b ? t : s;
87 }
88 }
89
90 class C {
91 // Check that the least upper bound of two types with the same
92 // class but different type arguments produces the pointwise
93 // least upper bound of the type arguments
94 int test1(bool b) {
95 List<int> li;
96 List<double> ld;
97 return /*warning:RETURN_OF_INVALID_TYPE*/b ? li : ld;
98 }
99 // TODO(leafp): This case isn't handled yet. This test checks
100 // the case where two related classes are instantiated with related
101 // but different types.
102 Iterable<num> test2(bool b) {
103 List<int> li;
104 Iterable<double> id;
105 int x =
106 /*info:ASSIGNMENT_CAST should be warning:INVALID_ASSIGNMENT*/
107 b ? li : id;
108 return /*warning:DOWN_CAST_COMPOSITE should be pass*/b ? li : id;
109 }
110 }
111 ''');
112 });
113
65 test('setter return types', () { 114 test('setter return types', () {
66 checkFile(''' 115 checkFile('''
67 void voidFn() => null; 116 void voidFn() => null;
68 class A { 117 class A {
69 set a(y) => 4; 118 set a(y) => 4;
70 set b(y) => voidFn(); 119 set b(y) => voidFn();
71 void set c(y) => /*warning:RETURN_OF_INVALID_TYPE*/4; 120 void set c(y) => /*warning:RETURN_OF_INVALID_TYPE*/4;
72 void set d(y) => voidFn(); 121 void set d(y) => voidFn();
73 /*warning:NON_VOID_RETURN_FOR_SETTER*/int set e(y) => 4; 122 /*warning:NON_VOID_RETURN_FOR_SETTER*/int set e(y) => 4;
74 /*warning:NON_VOID_RETURN_FOR_SETTER*/int set f(y) => /*warning:RETURN_O F_INVALID_TYPE*/voidFn(); 123 /*warning:NON_VOID_RETURN_FOR_SETTER*/int set f(y) =>
124 /*warning:RETURN_OF_INVALID_TYPE*/voidFn();
75 set g(y) {return /*warning:RETURN_OF_INVALID_TYPE*/4;} 125 set g(y) {return /*warning:RETURN_OF_INVALID_TYPE*/4;}
76 void set h(y) {return /*warning:RETURN_OF_INVALID_TYPE*/4;} 126 void set h(y) {return /*warning:RETURN_OF_INVALID_TYPE*/4;}
77 /*warning:NON_VOID_RETURN_FOR_SETTER*/int set i(y) {return 4;} 127 /*warning:NON_VOID_RETURN_FOR_SETTER*/int set i(y) {return 4;}
78 } 128 }
79 '''); 129 ''');
80 }); 130 });
81 131
82 test('if/for/do/while statements use boolean conversion', () { 132 test('if/for/do/while statements use boolean conversion', () {
83 checkFile(''' 133 checkFile('''
84 main() { 134 main() {
(...skipping 2910 matching lines...) Expand 10 before | Expand all | Expand 10 after
2995 3045
2996 baz1() sync* { yield* /*info:DYNAMIC_CAST*/x; } 3046 baz1() sync* { yield* /*info:DYNAMIC_CAST*/x; }
2997 Iterable baz2() sync* { yield* /*info:DYNAMIC_CAST*/x; } 3047 Iterable baz2() sync* { yield* /*info:DYNAMIC_CAST*/x; }
2998 Iterable<int> baz3() sync* { yield* /*warning:DOWN_CAST_COMPOSITE*/x; } 3048 Iterable<int> baz3() sync* { yield* /*warning:DOWN_CAST_COMPOSITE*/x; }
2999 Iterable<int> baz4() sync* { yield* bar3(); } 3049 Iterable<int> baz4() sync* { yield* bar3(); }
3000 Iterable<int> baz5() sync* { yield* /*info:INFERRED_TYPE_ALLOCATION*/new List(); } 3050 Iterable<int> baz5() sync* { yield* /*info:INFERRED_TYPE_ALLOCATION*/new List(); }
3001 '''); 3051 ''');
3002 }); 3052 });
3003 }); 3053 });
3004 } 3054 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698