| OLD | NEW |
| 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 test.src.task.strong.checker_test; | 8 library test.src.task.strong.checker_test; |
| 9 | 9 |
| 10 import 'package:unittest/unittest.dart'; | 10 import 'package:unittest/unittest.dart'; |
| 11 | 11 |
| 12 import 'strong_test_helper.dart'; | 12 import 'strong_test_helper.dart'; |
| 13 import 'package:analyzer/src/task/strong/info.dart'; |
| 13 | 14 |
| 14 void main() { | 15 void main() { |
| 16 |
| 15 testChecker('ternary operator', { | 17 testChecker('ternary operator', { |
| 16 '/main.dart': ''' | 18 '/main.dart': ''' |
| 17 abstract class Comparable<T> { | 19 abstract class Comparable<T> { |
| 18 int compareTo(T other); | 20 int compareTo(T other); |
| 19 static int compare(Comparable a, Comparable b) => a.compareTo(b); | 21 static int compare(Comparable a, Comparable b) => a.compareTo(b); |
| 20 } | 22 } |
| 21 typedef int Comparator<T>(T a, T b); | 23 typedef int Comparator<T>(T a, T b); |
| 22 | 24 |
| 23 typedef bool _Predicate<T>(T value); | 25 typedef bool _Predicate<T>(T value); |
| 24 | 26 |
| 25 class SplayTreeMap<K, V> { | 27 class SplayTreeMap<K, V> { |
| 26 Comparator<K> _comparator; | 28 Comparator<K> _comparator; |
| 27 _Predicate _validKey; | 29 _Predicate _validKey; |
| 28 | 30 |
| 29 // Initializing _comparator needs a cast, since K may not always be | 31 // Initializing _comparator needs a cast, since K may not always be |
| 30 // Comparable. | 32 // Comparable. |
| 31 // Initializing _validKey shouldn't need a cast. Currently | 33 // Initializing _validKey shouldn't need a cast. Currently |
| 32 // it requires inference to work because of dartbug.com/23381 | 34 // it requires inference to work because of dartbug.com/23381 |
| 33 SplayTreeMap([int compare(K key1, K key2), | 35 SplayTreeMap([int compare(K key1, K key2), |
| 34 bool isValidKey(potentialKey)]) { | 36 bool isValidKey(potentialKey)]) { |
| 35 : _comparator = /*warning:DownCastComposite*/(compare == null) | 37 : _comparator = /*warning:DOWN_CAST_COMPOSITE*/(compare == null) |
| 36 ? Comparable.compare : compare, | 38 ? Comparable.compare : compare, |
| 37 _validKey = /*warning:DownCastComposite*/(isValidKey != null) | 39 _validKey = /*warning:DOWN_CAST_COMPOSITE*/(isValidKey != null) |
| 38 ? isValidKey : ((v) => true); | 40 ? isValidKey : ((v) => true); |
| 39 _Predicate<Object> _v = /*warning:DownCastComposite*/(isValidKey !=
null) | 41 _Predicate<Object> _v = /*warning:DOWN_CAST_COMPOSITE*/(isValidKey
!= null) |
| 40 ? isValidKey : (/*info:InferredTypeClosure*/
(v) => true); | 42 ? isValidKey : (/*info:INFERRED_TYPE_CLOSURE
*/(v) => true); |
| 41 // TODO(leafp): Fix unimplemented LUB in analyzer | 43 // TODO(leafp): Fix unimplemented LUB in analyzer |
| 42 _v = /*warning:DownCastComposite*/(isValidKey != null) | 44 _v = /*warning:DOWN_CAST_COMPOSITE*/(isValidKey != null) |
| 43 ? _v : (/*info:InferredTypeClosure*/(v) => true); | 45 ? _v : (/*info:INFERRED_TYPE_CLOSURE*/(v) => true); |
| 44 } | 46 } |
| 45 } | 47 } |
| 46 void main() { | 48 void main() { |
| 47 Object obj = 42; | 49 Object obj = 42; |
| 48 dynamic dyn = 42; | 50 dynamic dyn = 42; |
| 49 int i = 42; | 51 int i = 42; |
| 50 | 52 |
| 51 // Check the boolean conversion of the condition. | 53 // Check the boolean conversion of the condition. |
| 52 print((/*severe:StaticTypeError*/i) ? false : true); | 54 print((/*severe:STATIC_TYPE_ERROR*/i) ? false : true); |
| 53 print((/*info:DownCastImplicit*/obj) ? false : true); | 55 print((/*info:DOWN_CAST_IMPLICIT*/obj) ? false : true); |
| 54 print((/*info:DynamicCast*/dyn) ? false : true); | 56 print((/*info:DYNAMIC_CAST*/dyn) ? false : true); |
| 55 } | 57 } |
| 56 ''' | 58 ''' |
| 57 }); | 59 }); |
| 58 | 60 |
| 59 testChecker('if/for/do/while statements use boolean conversion', { | 61 testChecker('if/for/do/while statements use boolean conversion', { |
| 60 '/main.dart': ''' | 62 '/main.dart': ''' |
| 61 main() { | 63 main() { |
| 62 dynamic d = 42; | 64 dynamic d = 42; |
| 63 Object obj = 42; | 65 Object obj = 42; |
| 64 int i = 42; | 66 int i = 42; |
| 65 bool b = false; | 67 bool b = false; |
| 66 | 68 |
| 67 if (b) {} | 69 if (b) {} |
| 68 if (/*info:DynamicCast*/dyn) {} | 70 if (/*info:DYNAMIC_CAST*/dyn) {} |
| 69 if (/*info:DownCastImplicit*/obj) {} | 71 if (/*info:DOWN_CAST_IMPLICIT*/obj) {} |
| 70 if (/*severe:StaticTypeError*/i) {} | 72 if (/*severe:STATIC_TYPE_ERROR*/i) {} |
| 71 | 73 |
| 72 while (b) {} | 74 while (b) {} |
| 73 while (/*info:DynamicCast*/dyn) {} | 75 while (/*info:DYNAMIC_CAST*/dyn) {} |
| 74 while (/*info:DownCastImplicit*/obj) {} | 76 while (/*info:DOWN_CAST_IMPLICIT*/obj) {} |
| 75 while (/*severe:StaticTypeError*/i) {} | 77 while (/*severe:STATIC_TYPE_ERROR*/i) {} |
| 76 | 78 |
| 77 do {} while (b); | 79 do {} while (b); |
| 78 do {} while (/*info:DynamicCast*/dyn); | 80 do {} while (/*info:DYNAMIC_CAST*/dyn); |
| 79 do {} while (/*info:DownCastImplicit*/obj); | 81 do {} while (/*info:DOWN_CAST_IMPLICIT*/obj); |
| 80 do {} while (/*severe:StaticTypeError*/i); | 82 do {} while (/*severe:STATIC_TYPE_ERROR*/i); |
| 81 | 83 |
| 82 for (;b;) {} | 84 for (;b;) {} |
| 83 for (;/*info:DynamicCast*/dyn;) {} | 85 for (;/*info:DYNAMIC_CAST*/dyn;) {} |
| 84 for (;/*info:DownCastImplicit*/obj;) {} | 86 for (;/*info:DOWN_CAST_IMPLICIT*/obj;) {} |
| 85 for (;/*severe:StaticTypeError*/i;) {} | 87 for (;/*severe:STATIC_TYPE_ERROR*/i;) {} |
| 86 } | 88 } |
| 87 ''' | 89 ''' |
| 88 }); | 90 }); |
| 89 | 91 |
| 90 testChecker('dynamic invocation', { | 92 testChecker('dynamic invocation', { |
| 91 '/main.dart': ''' | 93 '/main.dart': ''' |
| 92 | 94 |
| 93 class A { | 95 class A { |
| 94 dynamic call(dynamic x) => x; | 96 dynamic call(dynamic x) => x; |
| 95 } | 97 } |
| 96 class B extends A { | 98 class B extends A { |
| 97 int call(int x) => x; | 99 int call(int x) => x; |
| 98 double col(double x) => x; | 100 double col(double x) => x; |
| 99 } | 101 } |
| 100 void main() { | 102 void main() { |
| 101 { | 103 { |
| 102 B f = new B(); | 104 B f = new B(); |
| 103 int x; | 105 int x; |
| 104 double y; | 106 double y; |
| 105 // The analyzer has what I believe is a bug (dartbug.com/23252) which | 107 // The analyzer has what I believe is a bug (dartbug.com/23252) which |
| 106 // causes the return type of calls to f to be treated as dynamic. | 108 // causes the return type of calls to f to be treated as dynamic. |
| 107 x = /*info:DynamicCast should be pass*/f(3); | 109 x = /*info:DYNAMIC_CAST should be pass*/f(3); |
| 108 x = /*severe:StaticTypeError*/f.col(3.0); | 110 x = /*severe:STATIC_TYPE_ERROR*/f.col(3.0); |
| 109 y = /*info:DynamicCast should be severe:StaticTypeError*/f(3); | 111 y = /*info:DYNAMIC_CAST should be severe:STATIC_TYPE_ERROR*/f(3); |
| 110 y = f.col(3.0); | 112 y = f.col(3.0); |
| 111 f(/*severe:StaticTypeError*/3.0); | 113 f(/*severe:STATIC_TYPE_ERROR*/3.0); |
| 112 f.col(/*severe:StaticTypeError*/3); | 114 f.col(/*severe:STATIC_TYPE_ERROR*/3); |
| 113 } | 115 } |
| 114 { | 116 { |
| 115 Function f = new B(); | 117 Function f = new B(); |
| 116 int x; | 118 int x; |
| 117 double y; | 119 double y; |
| 118 x = /*info:DynamicCast, info:DynamicInvoke*/f(3); | 120 x = /*info:DYNAMIC_CAST, info:DYNAMIC_INVOKE*/f(3); |
| 119 x = /*info:DynamicCast, info:DynamicInvoke*/f.col(3.0); | 121 x = /*info:DYNAMIC_CAST, info:DYNAMIC_INVOKE*/f.col(3.0); |
| 120 y = /*info:DynamicCast, info:DynamicInvoke*/f(3); | 122 y = /*info:DYNAMIC_CAST, info:DYNAMIC_INVOKE*/f(3); |
| 121 y = /*info:DynamicCast, info:DynamicInvoke*/f.col(3.0); | 123 y = /*info:DYNAMIC_CAST, info:DYNAMIC_INVOKE*/f.col(3.0); |
| 122 (/*info:DynamicInvoke*/f(3.0)); | 124 (/*info:DYNAMIC_INVOKE*/f(3.0)); |
| 123 (/*info:DynamicInvoke*/f.col(3)); | 125 (/*info:DYNAMIC_INVOKE*/f.col(3)); |
| 124 } | 126 } |
| 125 { | 127 { |
| 126 A f = new B(); | 128 A f = new B(); |
| 127 int x; | 129 int x; |
| 128 double y; | 130 double y; |
| 129 x = /*info:DynamicCast, info:DynamicInvoke*/f(3); | 131 x = /*info:DYNAMIC_CAST, info:DYNAMIC_INVOKE*/f(3); |
| 130 y = /*info:DynamicCast, info:DynamicInvoke*/f(3); | 132 y = /*info:DYNAMIC_CAST, info:DYNAMIC_INVOKE*/f(3); |
| 131 (/*info:DynamicInvoke*/f(3.0)); | 133 (/*info:DYNAMIC_INVOKE*/f(3.0)); |
| 132 } | 134 } |
| 133 { | 135 { |
| 134 dynamic g = new B(); | 136 dynamic g = new B(); |
| 135 (/*info:DynamicInvoke*/g.call(32.0)); | 137 (/*info:DYNAMIC_INVOKE*/g.call(32.0)); |
| 136 (/*info:DynamicInvoke*/g.col(42.0)); | 138 (/*info:DYNAMIC_INVOKE*/g.col(42.0)); |
| 137 (/*info:DynamicInvoke*/g.foo(42.0)); | 139 (/*info:DYNAMIC_INVOKE*/g.foo(42.0)); |
| 138 (/*info:DynamicInvoke*/g.x); | 140 (/*info:DYNAMIC_INVOKE*/g.x); |
| 139 A f = new B(); | 141 A f = new B(); |
| 140 f.call(32.0); | 142 f.call(32.0); |
| 141 (/*info:DynamicInvoke*/f.col(42.0)); | 143 (/*info:DYNAMIC_INVOKE*/f.col(42.0)); |
| 142 (/*info:DynamicInvoke*/f.foo(42.0)); | 144 (/*info:DYNAMIC_INVOKE*/f.foo(42.0)); |
| 143 (/*info:DynamicInvoke*/f.x); | 145 (/*info:DYNAMIC_INVOKE*/f.x); |
| 144 } | 146 } |
| 145 } | 147 } |
| 146 ''' | 148 ''' |
| 147 }); | 149 }); |
| 148 | 150 |
| 149 testChecker('conversion and dynamic invoke', { | 151 testChecker('conversion and dynamic invoke', { |
| 150 '/helper.dart': ''' | 152 '/helper.dart': ''' |
| 151 dynamic toString = (int x) => x + 42; | 153 dynamic toString = (int x) => x + 42; |
| 152 dynamic hashCode = "hello"; | 154 dynamic hashCode = "hello"; |
| 153 ''', | 155 ''', |
| 154 '/main.dart': ''' | 156 '/main.dart': ''' |
| 155 import 'helper.dart' as helper; | 157 import 'helper.dart' as helper; |
| 156 | 158 |
| 157 class A { | 159 class A { |
| 158 String x = "hello world"; | 160 String x = "hello world"; |
| 159 | 161 |
| 160 void baz1(y) => x + /*info:DynamicCast*/y; | 162 void baz1(y) => x + /*info:DYNAMIC_CAST*/y; |
| 161 static baz2(y) => /*info:DynamicInvoke*/y + y; | 163 static baz2(y) => /*info:DYNAMIC_INVOKE*/y + y; |
| 162 } | 164 } |
| 163 | 165 |
| 164 void foo(String str) { | 166 void foo(String str) { |
| 165 print(str); | 167 print(str); |
| 166 } | 168 } |
| 167 | 169 |
| 168 class B { | 170 class B { |
| 169 String toString([int arg]) => arg.toString(); | 171 String toString([int arg]) => arg.toString(); |
| 170 } | 172 } |
| 171 | 173 |
| 172 void bar(a) { | 174 void bar(a) { |
| 173 foo(/*info:DynamicCast,info:DynamicInvoke*/a.x); | 175 foo(/*info:DYNAMIC_CAST,info:DYNAMIC_INVOKE*/a.x); |
| 174 } | 176 } |
| 175 | 177 |
| 176 baz() => new B(); | 178 baz() => new B(); |
| 177 | 179 |
| 178 typedef DynFun(x); | 180 typedef DynFun(x); |
| 179 typedef StrFun(String x); | 181 typedef StrFun(String x); |
| 180 | 182 |
| 181 var bar1 = bar; | 183 var bar1 = bar; |
| 182 | 184 |
| 183 void main() { | 185 void main() { |
| 184 var a = new A(); | 186 var a = new A(); |
| 185 bar(a); | 187 bar(a); |
| 186 (/*info:DynamicInvoke*/bar1(a)); | 188 (/*info:DYNAMIC_INVOKE*/bar1(a)); |
| 187 var b = bar; | 189 var b = bar; |
| 188 (/*info:DynamicInvoke*/b(a)); | 190 (/*info:DYNAMIC_INVOKE*/b(a)); |
| 189 var f1 = foo; | 191 var f1 = foo; |
| 190 f1("hello"); | 192 f1("hello"); |
| 191 dynamic f2 = foo; | 193 dynamic f2 = foo; |
| 192 (/*info:DynamicInvoke*/f2("hello")); | 194 (/*info:DYNAMIC_INVOKE*/f2("hello")); |
| 193 DynFun f3 = foo; | 195 DynFun f3 = foo; |
| 194 (/*info:DynamicInvoke*/f3("hello")); | 196 (/*info:DYNAMIC_INVOKE*/f3("hello")); |
| 195 (/*info:DynamicInvoke*/f3(42)); | 197 (/*info:DYNAMIC_INVOKE*/f3(42)); |
| 196 StrFun f4 = foo; | 198 StrFun f4 = foo; |
| 197 f4("hello"); | 199 f4("hello"); |
| 198 a.baz1("hello"); | 200 a.baz1("hello"); |
| 199 var b1 = a.baz1; | 201 var b1 = a.baz1; |
| 200 (/*info:DynamicInvoke*/b1("hello")); | 202 (/*info:DYNAMIC_INVOKE*/b1("hello")); |
| 201 A.baz2("hello"); | 203 A.baz2("hello"); |
| 202 var b2 = A.baz2; | 204 var b2 = A.baz2; |
| 203 (/*info:DynamicInvoke*/b2("hello")); | 205 (/*info:DYNAMIC_INVOKE*/b2("hello")); |
| 204 | 206 |
| 205 dynamic a1 = new B(); | 207 dynamic a1 = new B(); |
| 206 (/*info:DynamicInvoke*/a1.x); | 208 (/*info:DYNAMIC_INVOKE*/a1.x); |
| 207 a1.toString(); | 209 a1.toString(); |
| 208 (/*info:DynamicInvoke*/a1.toString(42)); | 210 (/*info:DYNAMIC_INVOKE*/a1.toString(42)); |
| 209 var toStringClosure = a1.toString; | 211 var toStringClosure = a1.toString; |
| 210 (/*info:DynamicInvoke*/a1.toStringClosure()); | 212 (/*info:DYNAMIC_INVOKE*/a1.toStringClosure()); |
| 211 (/*info:DynamicInvoke*/a1.toStringClosure(42)); | 213 (/*info:DYNAMIC_INVOKE*/a1.toStringClosure(42)); |
| 212 (/*info:DynamicInvoke*/a1.toStringClosure("hello")); | 214 (/*info:DYNAMIC_INVOKE*/a1.toStringClosure("hello")); |
| 213 a1.hashCode; | 215 a1.hashCode; |
| 214 | 216 |
| 215 dynamic toString = () => null; | 217 dynamic toString = () => null; |
| 216 (/*info:DynamicInvoke*/toString()); | 218 (/*info:DYNAMIC_INVOKE*/toString()); |
| 217 | 219 |
| 218 (/*info:DynamicInvoke*/helper.toString()); | 220 (/*info:DYNAMIC_INVOKE*/helper.toString()); |
| 219 var toStringClosure2 = helper.toString; | 221 var toStringClosure2 = helper.toString; |
| 220 (/*info:DynamicInvoke*/toStringClosure2()); | 222 (/*info:DYNAMIC_INVOKE*/toStringClosure2()); |
| 221 int hashCode = /*info:DynamicCast*/helper.hashCode; | 223 int hashCode = /*info:DYNAMIC_CAST*/helper.hashCode; |
| 222 | 224 |
| 223 baz().toString(); | 225 baz().toString(); |
| 224 baz().hashCode; | 226 baz().hashCode; |
| 225 } | 227 } |
| 226 ''' | 228 ''' |
| 227 }); | 229 }); |
| 228 | 230 |
| 229 testChecker('Constructors', { | 231 testChecker('Constructors', { |
| 230 '/main.dart': ''' | 232 '/main.dart': ''' |
| 231 const num z = 25; | 233 const num z = 25; |
| 232 Object obj = "world"; | 234 Object obj = "world"; |
| 233 | 235 |
| 234 class A { | 236 class A { |
| 235 int x; | 237 int x; |
| 236 String y; | 238 String y; |
| 237 | 239 |
| 238 A(this.x) : this.y = /*severe:StaticTypeError*/42; | 240 A(this.x) : this.y = /*severe:STATIC_TYPE_ERROR*/42; |
| 239 | 241 |
| 240 A.c1(p): this.x = /*info:DownCastImplicit*/z, this.y = /*info:DynamicCas
t*/p; | 242 A.c1(p): this.x = /*info:DOWN_CAST_IMPLICIT*/z, this.y = /*info:DYNAMIC_
CAST*/p; |
| 241 | 243 |
| 242 A.c2(this.x, this.y); | 244 A.c2(this.x, this.y); |
| 243 | 245 |
| 244 A.c3(/*severe:InvalidParameterDeclaration*/num this.x, String this.y); | 246 A.c3(/*severe:INVALID_PARAMETER_DECLARATION*/num this.x, String this.y); |
| 245 } | 247 } |
| 246 | 248 |
| 247 class B extends A { | 249 class B extends A { |
| 248 B() : super(/*severe:StaticTypeError*/"hello"); | 250 B() : super(/*severe:STATIC_TYPE_ERROR*/"hello"); |
| 249 | 251 |
| 250 B.c2(int x, String y) : super.c2(/*severe:StaticTypeError*/y, | 252 B.c2(int x, String y) : super.c2(/*severe:STATIC_TYPE_ERROR*/y, |
| 251 /*severe:StaticTypeError*/x); | 253 /*severe:STATIC_TYPE_ERROR*/x); |
| 252 | 254 |
| 253 B.c3(num x, Object y) : super.c3(x, /*info:DownCastImplicit*/y); | 255 B.c3(num x, Object y) : super.c3(x, /*info:DOWN_CAST_IMPLICIT*/y); |
| 254 } | 256 } |
| 255 | 257 |
| 256 void main() { | 258 void main() { |
| 257 A a = new A.c2(/*info:DownCastImplicit*/z, /*severe:StaticTypeError*/z)
; | 259 A a = new A.c2(/*info:DOWN_CAST_IMPLICIT*/z, /*severe:STATIC_TYPE_ERROR
*/z); |
| 258 var b = new B.c2(/*severe:StaticTypeError*/"hello", /*info:DownCastImpl
icit*/obj); | 260 var b = new B.c2(/*severe:STATIC_TYPE_ERROR*/"hello", /*info:DOWN_CAST_
IMPLICIT*/obj); |
| 259 } | 261 } |
| 260 ''' | 262 ''' |
| 261 }); | 263 }); |
| 262 | 264 |
| 263 testChecker('Unbound variable', { | 265 testChecker('Unbound variable', { |
| 264 '/main.dart': ''' | 266 '/main.dart': ''' |
| 265 void main() { | 267 void main() { |
| 266 dynamic y = /*pass should be severe:StaticTypeError*/unboundVariable; | 268 dynamic y = /*pass should be severe:STATIC_TYPE_ERROR*/unboundVariable; |
| 267 } | 269 } |
| 268 ''' | 270 ''' |
| 269 }); | 271 }); |
| 270 | 272 |
| 271 testChecker('Unbound type name', { | 273 testChecker('Unbound type name', { |
| 272 '/main.dart': ''' | 274 '/main.dart': ''' |
| 273 void main() { | 275 void main() { |
| 274 /*pass should be severe:StaticTypeError*/AToB y; | 276 /*pass should be severe:STATIC_TYPE_ERROR*/AToB y; |
| 275 } | 277 } |
| 276 ''' | 278 ''' |
| 277 }); | 279 }); |
| 278 | 280 |
| 279 testChecker('Ground type subtyping: dynamic is top', { | 281 testChecker('Ground type subtyping: dynamic is top', { |
| 280 '/main.dart': ''' | 282 '/main.dart': ''' |
| 281 | 283 |
| 282 class A {} | 284 class A {} |
| 283 class B extends A {} | 285 class B extends A {} |
| 284 | 286 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 308 | 310 |
| 309 void main() { | 311 void main() { |
| 310 dynamic y; | 312 dynamic y; |
| 311 Object o; | 313 Object o; |
| 312 int i = 0; | 314 int i = 0; |
| 313 double d = 0.0; | 315 double d = 0.0; |
| 314 num n; | 316 num n; |
| 315 A a; | 317 A a; |
| 316 B b; | 318 B b; |
| 317 o = y; | 319 o = y; |
| 318 i = /*info:DynamicCast*/y; | 320 i = /*info:DYNAMIC_CAST*/y; |
| 319 d = /*info:DynamicCast*/y; | 321 d = /*info:DYNAMIC_CAST*/y; |
| 320 n = /*info:DynamicCast*/y; | 322 n = /*info:DYNAMIC_CAST*/y; |
| 321 a = /*info:DynamicCast*/y; | 323 a = /*info:DYNAMIC_CAST*/y; |
| 322 b = /*info:DynamicCast*/y; | 324 b = /*info:DYNAMIC_CAST*/y; |
| 323 } | 325 } |
| 324 ''' | 326 ''' |
| 325 }); | 327 }); |
| 326 | 328 |
| 327 testChecker('Ground type subtyping: assigning a class', { | 329 testChecker('Ground type subtyping: assigning a class', { |
| 328 '/main.dart': ''' | 330 '/main.dart': ''' |
| 329 | 331 |
| 330 class A {} | 332 class A {} |
| 331 class B extends A {} | 333 class B extends A {} |
| 332 | 334 |
| 333 void main() { | 335 void main() { |
| 334 dynamic y; | 336 dynamic y; |
| 335 Object o; | 337 Object o; |
| 336 int i = 0; | 338 int i = 0; |
| 337 double d = 0.0; | 339 double d = 0.0; |
| 338 num n; | 340 num n; |
| 339 A a; | 341 A a; |
| 340 B b; | 342 B b; |
| 341 y = a; | 343 y = a; |
| 342 o = a; | 344 o = a; |
| 343 i = /*severe:StaticTypeError*/a; | 345 i = /*severe:STATIC_TYPE_ERROR*/a; |
| 344 d = /*severe:StaticTypeError*/a; | 346 d = /*severe:STATIC_TYPE_ERROR*/a; |
| 345 n = /*severe:StaticTypeError*/a; | 347 n = /*severe:STATIC_TYPE_ERROR*/a; |
| 346 a = a; | 348 a = a; |
| 347 b = /*info:DownCastImplicit*/a; | 349 b = /*info:DOWN_CAST_IMPLICIT*/a; |
| 348 } | 350 } |
| 349 ''' | 351 ''' |
| 350 }); | 352 }); |
| 351 | 353 |
| 352 testChecker('Ground type subtyping: assigning a subclass', { | 354 testChecker('Ground type subtyping: assigning a subclass', { |
| 353 '/main.dart': ''' | 355 '/main.dart': ''' |
| 354 | 356 |
| 355 class A {} | 357 class A {} |
| 356 class B extends A {} | 358 class B extends A {} |
| 357 class C extends A {} | 359 class C extends A {} |
| 358 | 360 |
| 359 void main() { | 361 void main() { |
| 360 dynamic y; | 362 dynamic y; |
| 361 Object o; | 363 Object o; |
| 362 int i = 0; | 364 int i = 0; |
| 363 double d = 0.0; | 365 double d = 0.0; |
| 364 num n; | 366 num n; |
| 365 A a; | 367 A a; |
| 366 B b; | 368 B b; |
| 367 C c; | 369 C c; |
| 368 y = b; | 370 y = b; |
| 369 o = b; | 371 o = b; |
| 370 i = /*severe:StaticTypeError*/b; | 372 i = /*severe:STATIC_TYPE_ERROR*/b; |
| 371 d = /*severe:StaticTypeError*/b; | 373 d = /*severe:STATIC_TYPE_ERROR*/b; |
| 372 n = /*severe:StaticTypeError*/b; | 374 n = /*severe:STATIC_TYPE_ERROR*/b; |
| 373 a = b; | 375 a = b; |
| 374 b = b; | 376 b = b; |
| 375 c = /*severe:StaticTypeError*/b; | 377 c = /*severe:STATIC_TYPE_ERROR*/b; |
| 376 } | 378 } |
| 377 ''' | 379 ''' |
| 378 }); | 380 }); |
| 379 | 381 |
| 380 testChecker('Ground type subtyping: interfaces', { | 382 testChecker('Ground type subtyping: interfaces', { |
| 381 '/main.dart': ''' | 383 '/main.dart': ''' |
| 382 | 384 |
| 383 class A {} | 385 class A {} |
| 384 class B extends A {} | 386 class B extends A {} |
| 385 class C extends A {} | 387 class C extends A {} |
| 386 class D extends B implements C {} | 388 class D extends B implements C {} |
| 387 | 389 |
| 388 void main() { | 390 void main() { |
| 389 A top; | 391 A top; |
| 390 B left; | 392 B left; |
| 391 C right; | 393 C right; |
| 392 D bot; | 394 D bot; |
| 393 { | 395 { |
| 394 top = top; | 396 top = top; |
| 395 top = left; | 397 top = left; |
| 396 top = right; | 398 top = right; |
| 397 top = bot; | 399 top = bot; |
| 398 } | 400 } |
| 399 { | 401 { |
| 400 left = /*info:DownCastImplicit*/top; | 402 left = /*info:DOWN_CAST_IMPLICIT*/top; |
| 401 left = left; | 403 left = left; |
| 402 left = /*severe:StaticTypeError*/right; | 404 left = /*severe:STATIC_TYPE_ERROR*/right; |
| 403 left = bot; | 405 left = bot; |
| 404 } | 406 } |
| 405 { | 407 { |
| 406 right = /*info:DownCastImplicit*/top; | 408 right = /*info:DOWN_CAST_IMPLICIT*/top; |
| 407 right = /*severe:StaticTypeError*/left; | 409 right = /*severe:STATIC_TYPE_ERROR*/left; |
| 408 right = right; | 410 right = right; |
| 409 right = bot; | 411 right = bot; |
| 410 } | 412 } |
| 411 { | 413 { |
| 412 bot = /*info:DownCastImplicit*/top; | 414 bot = /*info:DOWN_CAST_IMPLICIT*/top; |
| 413 bot = /*info:DownCastImplicit*/left; | 415 bot = /*info:DOWN_CAST_IMPLICIT*/left; |
| 414 bot = /*info:DownCastImplicit*/right; | 416 bot = /*info:DOWN_CAST_IMPLICIT*/right; |
| 415 bot = bot; | 417 bot = bot; |
| 416 } | 418 } |
| 417 } | 419 } |
| 418 ''' | 420 ''' |
| 419 }); | 421 }); |
| 420 | 422 |
| 421 testChecker('Function typing and subtyping: int and object', { | 423 testChecker('Function typing and subtyping: int and object', { |
| 422 '/main.dart': ''' | 424 '/main.dart': ''' |
| 423 | 425 |
| 424 typedef Object Top(int x); // Top of the lattice | 426 typedef Object Top(int x); // Top of the lattice |
| 425 typedef int Left(int x); // Left branch | 427 typedef int Left(int x); // Left branch |
| 426 typedef int Left2(int x); // Left branch | 428 typedef int Left2(int x); // Left branch |
| 427 typedef Object Right(Object x); // Right branch | 429 typedef Object Right(Object x); // Right branch |
| 428 typedef int Bot(Object x); // Bottom of the lattice | 430 typedef int Bot(Object x); // Bottom of the lattice |
| 429 | 431 |
| 430 Object top(int x) => x; | 432 Object top(int x) => x; |
| 431 int left(int x) => x; | 433 int left(int x) => x; |
| 432 Object right(Object x) => x; | 434 Object right(Object x) => x; |
| 433 int _bot(Object x) => /*info:DownCastImplicit*/x; | 435 int _bot(Object x) => /*info:DOWN_CAST_IMPLICIT*/x; |
| 434 int bot(Object x) => x as int; | 436 int bot(Object x) => x as int; |
| 435 | 437 |
| 436 void main() { | 438 void main() { |
| 437 { // Check typedef equality | 439 { // Check typedef equality |
| 438 Left f = left; | 440 Left f = left; |
| 439 Left2 g = f; | 441 Left2 g = f; |
| 440 } | 442 } |
| 441 { | 443 { |
| 442 Top f; | 444 Top f; |
| 443 f = top; | 445 f = top; |
| 444 f = left; | 446 f = left; |
| 445 f = right; | 447 f = right; |
| 446 f = bot; | 448 f = bot; |
| 447 } | 449 } |
| 448 { | 450 { |
| 449 Left f; | 451 Left f; |
| 450 f = /*warning:DownCastComposite*/top; | 452 f = /*warning:DOWN_CAST_COMPOSITE*/top; |
| 451 f = left; | 453 f = left; |
| 452 f = /*warning:DownCastComposite*/right; // Should we reject this? | 454 f = /*warning:DOWN_CAST_COMPOSITE*/right; // Should we reject this? |
| 453 f = bot; | 455 f = bot; |
| 454 } | 456 } |
| 455 { | 457 { |
| 456 Right f; | 458 Right f; |
| 457 f = /*warning:DownCastComposite*/top; | 459 f = /*warning:DOWN_CAST_COMPOSITE*/top; |
| 458 f = /*warning:DownCastComposite*/left; // Should we reject this? | 460 f = /*warning:DOWN_CAST_COMPOSITE*/left; // Should we reject this? |
| 459 f = right; | 461 f = right; |
| 460 f = bot; | 462 f = bot; |
| 461 } | 463 } |
| 462 { | 464 { |
| 463 Bot f; | 465 Bot f; |
| 464 f = /*warning:DownCastComposite*/top; | 466 f = /*warning:DOWN_CAST_COMPOSITE*/top; |
| 465 f = /*warning:DownCastComposite*/left; | 467 f = /*warning:DOWN_CAST_COMPOSITE*/left; |
| 466 f = /*warning:DownCastComposite*/right; | 468 f = /*warning:DOWN_CAST_COMPOSITE*/right; |
| 467 f = bot; | 469 f = bot; |
| 468 } | 470 } |
| 469 } | 471 } |
| 470 ''' | 472 ''' |
| 471 }); | 473 }); |
| 472 | 474 |
| 473 testChecker('Function typing and subtyping: classes', { | 475 testChecker('Function typing and subtyping: classes', { |
| 474 '/main.dart': ''' | 476 '/main.dart': ''' |
| 475 | 477 |
| 476 class A {} | 478 class A {} |
| 477 class B extends A {} | 479 class B extends A {} |
| 478 | 480 |
| 479 typedef A Top(B x); // Top of the lattice | 481 typedef A Top(B x); // Top of the lattice |
| 480 typedef B Left(B x); // Left branch | 482 typedef B Left(B x); // Left branch |
| 481 typedef B Left2(B x); // Left branch | 483 typedef B Left2(B x); // Left branch |
| 482 typedef A Right(A x); // Right branch | 484 typedef A Right(A x); // Right branch |
| 483 typedef B Bot(A x); // Bottom of the lattice | 485 typedef B Bot(A x); // Bottom of the lattice |
| 484 | 486 |
| 485 B left(B x) => x; | 487 B left(B x) => x; |
| 486 B _bot(A x) => /*info:DownCastImplicit*/x; | 488 B _bot(A x) => /*info:DOWN_CAST_IMPLICIT*/x; |
| 487 B bot(A x) => x as B; | 489 B bot(A x) => x as B; |
| 488 A top(B x) => x; | 490 A top(B x) => x; |
| 489 A right(A x) => x; | 491 A right(A x) => x; |
| 490 | 492 |
| 491 void main() { | 493 void main() { |
| 492 { // Check typedef equality | 494 { // Check typedef equality |
| 493 Left f = left; | 495 Left f = left; |
| 494 Left2 g = f; | 496 Left2 g = f; |
| 495 } | 497 } |
| 496 { | 498 { |
| 497 Top f; | 499 Top f; |
| 498 f = top; | 500 f = top; |
| 499 f = left; | 501 f = left; |
| 500 f = right; | 502 f = right; |
| 501 f = bot; | 503 f = bot; |
| 502 } | 504 } |
| 503 { | 505 { |
| 504 Left f; | 506 Left f; |
| 505 f = /*warning:DownCastComposite*/top; | 507 f = /*warning:DOWN_CAST_COMPOSITE*/top; |
| 506 f = left; | 508 f = left; |
| 507 f = /*warning:DownCastComposite*/right; // Should we reject this? | 509 f = /*warning:DOWN_CAST_COMPOSITE*/right; // Should we reject this? |
| 508 f = bot; | 510 f = bot; |
| 509 } | 511 } |
| 510 { | 512 { |
| 511 Right f; | 513 Right f; |
| 512 f = /*warning:DownCastComposite*/top; | 514 f = /*warning:DOWN_CAST_COMPOSITE*/top; |
| 513 f = /*warning:DownCastComposite*/left; // Should we reject this? | 515 f = /*warning:DOWN_CAST_COMPOSITE*/left; // Should we reject this? |
| 514 f = right; | 516 f = right; |
| 515 f = bot; | 517 f = bot; |
| 516 } | 518 } |
| 517 { | 519 { |
| 518 Bot f; | 520 Bot f; |
| 519 f = /*warning:DownCastComposite*/top; | 521 f = /*warning:DOWN_CAST_COMPOSITE*/top; |
| 520 f = /*warning:DownCastComposite*/left; | 522 f = /*warning:DOWN_CAST_COMPOSITE*/left; |
| 521 f = /*warning:DownCastComposite*/right; | 523 f = /*warning:DOWN_CAST_COMPOSITE*/right; |
| 522 f = bot; | 524 f = bot; |
| 523 } | 525 } |
| 524 } | 526 } |
| 525 ''' | 527 ''' |
| 526 }); | 528 }); |
| 527 | 529 |
| 528 testChecker('Function typing and subtyping: dynamic', { | 530 testChecker('Function typing and subtyping: dynamic', { |
| 529 '/main.dart': ''' | 531 '/main.dart': ''' |
| 530 | 532 |
| 531 class A {} | 533 class A {} |
| 532 | 534 |
| 533 typedef dynamic Top(dynamic x); // Top of the lattice | 535 typedef dynamic Top(dynamic x); // Top of the lattice |
| 534 typedef dynamic Left(A x); // Left branch | 536 typedef dynamic Left(A x); // Left branch |
| 535 typedef A Right(dynamic x); // Right branch | 537 typedef A Right(dynamic x); // Right branch |
| 536 typedef A Bottom(A x); // Bottom of the lattice | 538 typedef A Bottom(A x); // Bottom of the lattice |
| 537 | 539 |
| 538 dynamic left(A x) => x; | 540 dynamic left(A x) => x; |
| 539 A bot(A x) => x; | 541 A bot(A x) => x; |
| 540 dynamic top(dynamic x) => x; | 542 dynamic top(dynamic x) => x; |
| 541 A right(dynamic x) => /*info:DynamicCast*/x; | 543 A right(dynamic x) => /*info:DYNAMIC_CAST*/x; |
| 542 | 544 |
| 543 void main() { | 545 void main() { |
| 544 { | 546 { |
| 545 Top f; | 547 Top f; |
| 546 f = top; | 548 f = top; |
| 547 f = left; | 549 f = left; |
| 548 f = right; | 550 f = right; |
| 549 f = bot; | 551 f = bot; |
| 550 } | 552 } |
| 551 { | 553 { |
| 552 Left f; | 554 Left f; |
| 553 f = /*warning:DownCastComposite*/top; | 555 f = /*warning:DOWN_CAST_COMPOSITE*/top; |
| 554 f = left; | 556 f = left; |
| 555 f = /*warning:DownCastComposite*/right; | 557 f = /*warning:DOWN_CAST_COMPOSITE*/right; |
| 556 f = bot; | 558 f = bot; |
| 557 } | 559 } |
| 558 { | 560 { |
| 559 Right f; | 561 Right f; |
| 560 f = /*warning:DownCastComposite*/top; | 562 f = /*warning:DOWN_CAST_COMPOSITE*/top; |
| 561 f = /*warning:DownCastComposite*/left; | 563 f = /*warning:DOWN_CAST_COMPOSITE*/left; |
| 562 f = right; | 564 f = right; |
| 563 f = bot; | 565 f = bot; |
| 564 } | 566 } |
| 565 { | 567 { |
| 566 Bottom f; | 568 Bottom f; |
| 567 f = /*warning:DownCastComposite*/top; | 569 f = /*warning:DOWN_CAST_COMPOSITE*/top; |
| 568 f = /*warning:DownCastComposite*/left; | 570 f = /*warning:DOWN_CAST_COMPOSITE*/left; |
| 569 f = /*warning:DownCastComposite*/right; | 571 f = /*warning:DOWN_CAST_COMPOSITE*/right; |
| 570 f = bot; | 572 f = bot; |
| 571 } | 573 } |
| 572 } | 574 } |
| 573 ''' | 575 ''' |
| 574 }); | 576 }); |
| 575 | 577 |
| 576 testChecker('Function typing and subtyping: function literal variance', { | 578 testChecker('Function typing and subtyping: function literal variance', { |
| 577 '/main.dart': ''' | 579 '/main.dart': ''' |
| 578 | 580 |
| 579 class A {} | 581 class A {} |
| 580 class B extends A {} | 582 class B extends A {} |
| 581 | 583 |
| 582 typedef T Function2<S, T>(S z); | 584 typedef T Function2<S, T>(S z); |
| 583 | 585 |
| 584 A top(B x) => x; | 586 A top(B x) => x; |
| 585 B left(B x) => x; | 587 B left(B x) => x; |
| 586 A right(A x) => x; | 588 A right(A x) => x; |
| 587 B bot(A x) => x as B; | 589 B bot(A x) => x as B; |
| 588 | 590 |
| 589 void main() { | 591 void main() { |
| 590 { | 592 { |
| 591 Function2<B, A> f; | 593 Function2<B, A> f; |
| 592 f = top; | 594 f = top; |
| 593 f = left; | 595 f = left; |
| 594 f = right; | 596 f = right; |
| 595 f = bot; | 597 f = bot; |
| 596 } | 598 } |
| 597 { | 599 { |
| 598 Function2<B, B> f; | 600 Function2<B, B> f; |
| 599 f = /*warning:DownCastComposite*/top; | 601 f = /*warning:DOWN_CAST_COMPOSITE*/top; |
| 600 f = left; | 602 f = left; |
| 601 f = /*warning:DownCastComposite*/right; // Should we reject this? | 603 f = /*warning:DOWN_CAST_COMPOSITE*/right; // Should we reject this? |
| 602 f = bot; | 604 f = bot; |
| 603 } | 605 } |
| 604 { | 606 { |
| 605 Function2<A, A> f; | 607 Function2<A, A> f; |
| 606 f = /*warning:DownCastComposite*/top; | 608 f = /*warning:DOWN_CAST_COMPOSITE*/top; |
| 607 f = /*warning:DownCastComposite*/left; // Should we reject this? | 609 f = /*warning:DOWN_CAST_COMPOSITE*/left; // Should we reject this? |
| 608 f = right; | 610 f = right; |
| 609 f = bot; | 611 f = bot; |
| 610 } | 612 } |
| 611 { | 613 { |
| 612 Function2<A, B> f; | 614 Function2<A, B> f; |
| 613 f = /*warning:DownCastComposite*/top; | 615 f = /*warning:DOWN_CAST_COMPOSITE*/top; |
| 614 f = /*warning:DownCastComposite*/left; | 616 f = /*warning:DOWN_CAST_COMPOSITE*/left; |
| 615 f = /*warning:DownCastComposite*/right; | 617 f = /*warning:DOWN_CAST_COMPOSITE*/right; |
| 616 f = bot; | 618 f = bot; |
| 617 } | 619 } |
| 618 } | 620 } |
| 619 ''' | 621 ''' |
| 620 }); | 622 }); |
| 621 | 623 |
| 622 testChecker('Function typing and subtyping: function variable variance', { | 624 testChecker('Function typing and subtyping: function variable variance', { |
| 623 '/main.dart': ''' | 625 '/main.dart': ''' |
| 624 | 626 |
| 625 class A {} | 627 class A {} |
| 626 class B extends A {} | 628 class B extends A {} |
| 627 | 629 |
| 628 typedef T Function2<S, T>(S z); | 630 typedef T Function2<S, T>(S z); |
| 629 | 631 |
| 630 void main() { | 632 void main() { |
| 631 { | 633 { |
| 632 Function2<B, A> top; | 634 Function2<B, A> top; |
| 633 Function2<B, B> left; | 635 Function2<B, B> left; |
| 634 Function2<A, A> right; | 636 Function2<A, A> right; |
| 635 Function2<A, B> bot; | 637 Function2<A, B> bot; |
| 636 | 638 |
| 637 top = right; | 639 top = right; |
| 638 top = bot; | 640 top = bot; |
| 639 top = top; | 641 top = top; |
| 640 top = left; | 642 top = left; |
| 641 | 643 |
| 642 left = /*warning:DownCastComposite*/top; | 644 left = /*warning:DOWN_CAST_COMPOSITE*/top; |
| 643 left = left; | 645 left = left; |
| 644 left = /*warning:DownCastComposite*/right; // Should we reject this? | 646 left = /*warning:DOWN_CAST_COMPOSITE*/right; // Should we reject this? |
| 645 left = bot; | 647 left = bot; |
| 646 | 648 |
| 647 right = /*warning:DownCastComposite*/top; | 649 right = /*warning:DOWN_CAST_COMPOSITE*/top; |
| 648 right = /*warning:DownCastComposite*/left; // Should we reject this? | 650 right = /*warning:DOWN_CAST_COMPOSITE*/left; // Should we reject this? |
| 649 right = right; | 651 right = right; |
| 650 right = bot; | 652 right = bot; |
| 651 | 653 |
| 652 bot = /*warning:DownCastComposite*/top; | 654 bot = /*warning:DOWN_CAST_COMPOSITE*/top; |
| 653 bot = /*warning:DownCastComposite*/left; | 655 bot = /*warning:DOWN_CAST_COMPOSITE*/left; |
| 654 bot = /*warning:DownCastComposite*/right; | 656 bot = /*warning:DOWN_CAST_COMPOSITE*/right; |
| 655 bot = bot; | 657 bot = bot; |
| 656 } | 658 } |
| 657 } | 659 } |
| 658 ''' | 660 ''' |
| 659 }); | 661 }); |
| 660 | 662 |
| 661 testChecker('Function typing and subtyping: higher order function literals', { | 663 testChecker('Function typing and subtyping: higher order function literals', { |
| 662 '/main.dart': ''' | 664 '/main.dart': ''' |
| 663 | 665 |
| 664 class A {} | 666 class A {} |
| 665 class B extends A {} | 667 class B extends A {} |
| 666 | 668 |
| 667 typedef T Function2<S, T>(S z); | 669 typedef T Function2<S, T>(S z); |
| 668 | 670 |
| 669 typedef A BToA(B x); // Top of the base lattice | 671 typedef A BToA(B x); // Top of the base lattice |
| 670 typedef B AToB(A x); // Bot of the base lattice | 672 typedef B AToB(A x); // Bot of the base lattice |
| 671 | 673 |
| 672 BToA top(AToB f) => f; | 674 BToA top(AToB f) => f; |
| 673 AToB left(AToB f) => f; | 675 AToB left(AToB f) => f; |
| 674 BToA right(BToA f) => f; | 676 BToA right(BToA f) => f; |
| 675 AToB _bot(BToA f) => /*warning:DownCastComposite*/f; | 677 AToB _bot(BToA f) => /*warning:DOWN_CAST_COMPOSITE*/f; |
| 676 AToB bot(BToA f) => f as AToB; | 678 AToB bot(BToA f) => f as AToB; |
| 677 | 679 |
| 678 Function2<B, A> top(AToB f) => f; | 680 Function2<B, A> top(AToB f) => f; |
| 679 Function2<A, B> left(AToB f) => f; | 681 Function2<A, B> left(AToB f) => f; |
| 680 Function2<B, A> right(BToA f) => f; | 682 Function2<B, A> right(BToA f) => f; |
| 681 Function2<A, B> _bot(BToA f) => /*warning:DownCastComposite*/f; | 683 Function2<A, B> _bot(BToA f) => /*warning:DOWN_CAST_COMPOSITE*/f; |
| 682 Function2<A, B> bot(BToA f) => f as Function2<A, B>; | 684 Function2<A, B> bot(BToA f) => f as Function2<A, B>; |
| 683 | 685 |
| 684 | 686 |
| 685 BToA top(Function2<A, B> f) => f; | 687 BToA top(Function2<A, B> f) => f; |
| 686 AToB left(Function2<A, B> f) => f; | 688 AToB left(Function2<A, B> f) => f; |
| 687 BToA right(Function2<B, A> f) => f; | 689 BToA right(Function2<B, A> f) => f; |
| 688 AToB _bot(Function2<B, A> f) => /*warning:DownCastComposite*/f; | 690 AToB _bot(Function2<B, A> f) => /*warning:DOWN_CAST_COMPOSITE*/f; |
| 689 AToB bot(Function2<B, A> f) => f as AToB; | 691 AToB bot(Function2<B, A> f) => f as AToB; |
| 690 | 692 |
| 691 void main() { | 693 void main() { |
| 692 { | 694 { |
| 693 Function2<AToB, BToA> f; // Top | 695 Function2<AToB, BToA> f; // Top |
| 694 f = top; | 696 f = top; |
| 695 f = left; | 697 f = left; |
| 696 f = right; | 698 f = right; |
| 697 f = bot; | 699 f = bot; |
| 698 } | 700 } |
| 699 { | 701 { |
| 700 Function2<AToB, AToB> f; // Left | 702 Function2<AToB, AToB> f; // Left |
| 701 f = /*warning:DownCastComposite*/top; | 703 f = /*warning:DOWN_CAST_COMPOSITE*/top; |
| 702 f = left; | 704 f = left; |
| 703 f = /*warning:DownCastComposite*/right; // Should we reject this? | 705 f = /*warning:DOWN_CAST_COMPOSITE*/right; // Should we reject this? |
| 704 f = bot; | 706 f = bot; |
| 705 } | 707 } |
| 706 { | 708 { |
| 707 Function2<BToA, BToA> f; // Right | 709 Function2<BToA, BToA> f; // Right |
| 708 f = /*warning:DownCastComposite*/top; | 710 f = /*warning:DOWN_CAST_COMPOSITE*/top; |
| 709 f = /*warning:DownCastComposite*/left; // Should we reject this? | 711 f = /*warning:DOWN_CAST_COMPOSITE*/left; // Should we reject this? |
| 710 f = right; | 712 f = right; |
| 711 f = bot; | 713 f = bot; |
| 712 } | 714 } |
| 713 { | 715 { |
| 714 Function2<BToA, AToB> f; // Bot | 716 Function2<BToA, AToB> f; // Bot |
| 715 f = bot; | 717 f = bot; |
| 716 f = /*warning:DownCastComposite*/left; | 718 f = /*warning:DOWN_CAST_COMPOSITE*/left; |
| 717 f = /*warning:DownCastComposite*/top; | 719 f = /*warning:DOWN_CAST_COMPOSITE*/top; |
| 718 f = /*warning:DownCastComposite*/left; | 720 f = /*warning:DOWN_CAST_COMPOSITE*/left; |
| 719 } | 721 } |
| 720 } | 722 } |
| 721 ''' | 723 ''' |
| 722 }); | 724 }); |
| 723 | 725 |
| 724 testChecker( | 726 testChecker( |
| 725 'Function typing and subtyping: higher order function variables', { | 727 'Function typing and subtyping: higher order function variables', { |
| 726 '/main.dart': ''' | 728 '/main.dart': ''' |
| 727 | 729 |
| 728 class A {} | 730 class A {} |
| 729 class B extends A {} | 731 class B extends A {} |
| 730 | 732 |
| 731 typedef T Function2<S, T>(S z); | 733 typedef T Function2<S, T>(S z); |
| 732 | 734 |
| 733 void main() { | 735 void main() { |
| 734 { | 736 { |
| 735 Function2<Function2<A, B>, Function2<B, A>> top; | 737 Function2<Function2<A, B>, Function2<B, A>> top; |
| 736 Function2<Function2<B, A>, Function2<B, A>> right; | 738 Function2<Function2<B, A>, Function2<B, A>> right; |
| 737 Function2<Function2<A, B>, Function2<A, B>> left; | 739 Function2<Function2<A, B>, Function2<A, B>> left; |
| 738 Function2<Function2<B, A>, Function2<A, B>> bot; | 740 Function2<Function2<B, A>, Function2<A, B>> bot; |
| 739 | 741 |
| 740 top = right; | 742 top = right; |
| 741 top = bot; | 743 top = bot; |
| 742 top = top; | 744 top = top; |
| 743 top = left; | 745 top = left; |
| 744 | 746 |
| 745 left = /*warning:DownCastComposite*/top; | 747 left = /*warning:DOWN_CAST_COMPOSITE*/top; |
| 746 left = left; | 748 left = left; |
| 747 left = | 749 left = |
| 748 /*warning:DownCastComposite should be severe:StaticTypeError*/right; | 750 /*warning:DOWN_CAST_COMPOSITE should be severe:STATIC_TYPE_ERROR*/ri
ght; |
| 749 left = bot; | 751 left = bot; |
| 750 | 752 |
| 751 right = /*warning:DownCastComposite*/top; | 753 right = /*warning:DOWN_CAST_COMPOSITE*/top; |
| 752 right = | 754 right = |
| 753 /*warning:DownCastComposite should be severe:StaticTypeError*/left; | 755 /*warning:DOWN_CAST_COMPOSITE should be severe:STATIC_TYPE_ERROR*/le
ft; |
| 754 right = right; | 756 right = right; |
| 755 right = bot; | 757 right = bot; |
| 756 | 758 |
| 757 bot = /*warning:DownCastComposite*/top; | 759 bot = /*warning:DOWN_CAST_COMPOSITE*/top; |
| 758 bot = /*warning:DownCastComposite*/left; | 760 bot = /*warning:DOWN_CAST_COMPOSITE*/left; |
| 759 bot = /*warning:DownCastComposite*/right; | 761 bot = /*warning:DOWN_CAST_COMPOSITE*/right; |
| 760 bot = bot; | 762 bot = bot; |
| 761 } | 763 } |
| 762 } | 764 } |
| 763 ''' | 765 ''' |
| 764 }); | 766 }); |
| 765 | 767 |
| 766 testChecker('Function typing and subtyping: named and optional parameters', { | 768 testChecker('Function typing and subtyping: named and optional parameters', { |
| 767 '/main.dart': ''' | 769 '/main.dart': ''' |
| 768 | 770 |
| 769 class A {} | 771 class A {} |
| (...skipping 14 matching lines...) Expand all Loading... |
| 784 FN n; | 786 FN n; |
| 785 FRR rr; | 787 FRR rr; |
| 786 FRO ro; | 788 FRO ro; |
| 787 FRN rn; | 789 FRN rn; |
| 788 FOO oo; | 790 FOO oo; |
| 789 FNN nn; | 791 FNN nn; |
| 790 FNNN nnn; | 792 FNNN nnn; |
| 791 | 793 |
| 792 r = r; | 794 r = r; |
| 793 r = o; | 795 r = o; |
| 794 r = /*severe:StaticTypeError*/n; | 796 r = /*severe:STATIC_TYPE_ERROR*/n; |
| 795 r = /*severe:StaticTypeError*/rr; | 797 r = /*severe:STATIC_TYPE_ERROR*/rr; |
| 796 r = ro; | 798 r = ro; |
| 797 r = rn; | 799 r = rn; |
| 798 r = oo; | 800 r = oo; |
| 799 r = /*severe:StaticTypeError*/nn; | 801 r = /*severe:STATIC_TYPE_ERROR*/nn; |
| 800 r = /*severe:StaticTypeError*/nnn; | 802 r = /*severe:STATIC_TYPE_ERROR*/nnn; |
| 801 | 803 |
| 802 o = /*warning:DownCastComposite*/r; | 804 o = /*warning:DOWN_CAST_COMPOSITE*/r; |
| 803 o = o; | 805 o = o; |
| 804 o = /*severe:StaticTypeError*/n; | 806 o = /*severe:STATIC_TYPE_ERROR*/n; |
| 805 o = /*severe:StaticTypeError*/rr; | 807 o = /*severe:STATIC_TYPE_ERROR*/rr; |
| 806 o = /*severe:StaticTypeError*/ro; | 808 o = /*severe:STATIC_TYPE_ERROR*/ro; |
| 807 o = /*severe:StaticTypeError*/rn; | 809 o = /*severe:STATIC_TYPE_ERROR*/rn; |
| 808 o = oo; | 810 o = oo; |
| 809 o = /*severe:StaticTypeError*/nn | 811 o = /*severe:STATIC_TYPE_ERROR*/nn |
| 810 o = /*severe:StaticTypeError*/nnn; | 812 o = /*severe:STATIC_TYPE_ERROR*/nnn; |
| 811 | 813 |
| 812 n = /*severe:StaticTypeError*/r; | 814 n = /*severe:STATIC_TYPE_ERROR*/r; |
| 813 n = /*severe:StaticTypeError*/o; | 815 n = /*severe:STATIC_TYPE_ERROR*/o; |
| 814 n = n; | 816 n = n; |
| 815 n = /*severe:StaticTypeError*/rr; | 817 n = /*severe:STATIC_TYPE_ERROR*/rr; |
| 816 n = /*severe:StaticTypeError*/ro; | 818 n = /*severe:STATIC_TYPE_ERROR*/ro; |
| 817 n = /*severe:StaticTypeError*/rn; | 819 n = /*severe:STATIC_TYPE_ERROR*/rn; |
| 818 n = /*severe:StaticTypeError*/oo; | 820 n = /*severe:STATIC_TYPE_ERROR*/oo; |
| 819 n = nn; | 821 n = nn; |
| 820 n = nnn; | 822 n = nnn; |
| 821 | 823 |
| 822 rr = /*severe:StaticTypeError*/r; | 824 rr = /*severe:STATIC_TYPE_ERROR*/r; |
| 823 rr = /*severe:StaticTypeError*/o; | 825 rr = /*severe:STATIC_TYPE_ERROR*/o; |
| 824 rr = /*severe:StaticTypeError*/n; | 826 rr = /*severe:STATIC_TYPE_ERROR*/n; |
| 825 rr = rr; | 827 rr = rr; |
| 826 rr = ro; | 828 rr = ro; |
| 827 rr = /*severe:StaticTypeError*/rn; | 829 rr = /*severe:STATIC_TYPE_ERROR*/rn; |
| 828 rr = oo; | 830 rr = oo; |
| 829 rr = /*severe:StaticTypeError*/nn; | 831 rr = /*severe:STATIC_TYPE_ERROR*/nn; |
| 830 rr = /*severe:StaticTypeError*/nnn; | 832 rr = /*severe:STATIC_TYPE_ERROR*/nnn; |
| 831 | 833 |
| 832 ro = /*warning:DownCastComposite*/r; | 834 ro = /*warning:DOWN_CAST_COMPOSITE*/r; |
| 833 ro = /*severe:StaticTypeError*/o; | 835 ro = /*severe:STATIC_TYPE_ERROR*/o; |
| 834 ro = /*severe:StaticTypeError*/n; | 836 ro = /*severe:STATIC_TYPE_ERROR*/n; |
| 835 ro = /*warning:DownCastComposite*/rr; | 837 ro = /*warning:DOWN_CAST_COMPOSITE*/rr; |
| 836 ro = ro; | 838 ro = ro; |
| 837 ro = /*severe:StaticTypeError*/rn; | 839 ro = /*severe:STATIC_TYPE_ERROR*/rn; |
| 838 ro = oo; | 840 ro = oo; |
| 839 ro = /*severe:StaticTypeError*/nn; | 841 ro = /*severe:STATIC_TYPE_ERROR*/nn; |
| 840 ro = /*severe:StaticTypeError*/nnn; | 842 ro = /*severe:STATIC_TYPE_ERROR*/nnn; |
| 841 | 843 |
| 842 rn = /*warning:DownCastComposite*/r; | 844 rn = /*warning:DOWN_CAST_COMPOSITE*/r; |
| 843 rn = /*severe:StaticTypeError*/o; | 845 rn = /*severe:STATIC_TYPE_ERROR*/o; |
| 844 rn = /*severe:StaticTypeError*/n; | 846 rn = /*severe:STATIC_TYPE_ERROR*/n; |
| 845 rn = /*severe:StaticTypeError*/rr; | 847 rn = /*severe:STATIC_TYPE_ERROR*/rr; |
| 846 rn = /*severe:StaticTypeError*/ro; | 848 rn = /*severe:STATIC_TYPE_ERROR*/ro; |
| 847 rn = rn; | 849 rn = rn; |
| 848 rn = /*severe:StaticTypeError*/oo; | 850 rn = /*severe:STATIC_TYPE_ERROR*/oo; |
| 849 rn = /*severe:StaticTypeError*/nn; | 851 rn = /*severe:STATIC_TYPE_ERROR*/nn; |
| 850 rn = /*severe:StaticTypeError*/nnn; | 852 rn = /*severe:STATIC_TYPE_ERROR*/nnn; |
| 851 | 853 |
| 852 oo = /*warning:DownCastComposite*/r; | 854 oo = /*warning:DOWN_CAST_COMPOSITE*/r; |
| 853 oo = /*warning:DownCastComposite*/o; | 855 oo = /*warning:DOWN_CAST_COMPOSITE*/o; |
| 854 oo = /*severe:StaticTypeError*/n; | 856 oo = /*severe:STATIC_TYPE_ERROR*/n; |
| 855 oo = /*warning:DownCastComposite*/rr; | 857 oo = /*warning:DOWN_CAST_COMPOSITE*/rr; |
| 856 oo = /*warning:DownCastComposite*/ro; | 858 oo = /*warning:DOWN_CAST_COMPOSITE*/ro; |
| 857 oo = /*severe:StaticTypeError*/rn; | 859 oo = /*severe:STATIC_TYPE_ERROR*/rn; |
| 858 oo = oo; | 860 oo = oo; |
| 859 oo = /*severe:StaticTypeError*/nn; | 861 oo = /*severe:STATIC_TYPE_ERROR*/nn; |
| 860 oo = /*severe:StaticTypeError*/nnn; | 862 oo = /*severe:STATIC_TYPE_ERROR*/nnn; |
| 861 | 863 |
| 862 nn = /*severe:StaticTypeError*/r; | 864 nn = /*severe:STATIC_TYPE_ERROR*/r; |
| 863 nn = /*severe:StaticTypeError*/o; | 865 nn = /*severe:STATIC_TYPE_ERROR*/o; |
| 864 nn = /*warning:DownCastComposite*/n; | 866 nn = /*warning:DOWN_CAST_COMPOSITE*/n; |
| 865 nn = /*severe:StaticTypeError*/rr; | 867 nn = /*severe:STATIC_TYPE_ERROR*/rr; |
| 866 nn = /*severe:StaticTypeError*/ro; | 868 nn = /*severe:STATIC_TYPE_ERROR*/ro; |
| 867 nn = /*severe:StaticTypeError*/rn; | 869 nn = /*severe:STATIC_TYPE_ERROR*/rn; |
| 868 nn = /*severe:StaticTypeError*/oo; | 870 nn = /*severe:STATIC_TYPE_ERROR*/oo; |
| 869 nn = nn; | 871 nn = nn; |
| 870 nn = nnn; | 872 nn = nnn; |
| 871 | 873 |
| 872 nnn = /*severe:StaticTypeError*/r; | 874 nnn = /*severe:STATIC_TYPE_ERROR*/r; |
| 873 nnn = /*severe:StaticTypeError*/o; | 875 nnn = /*severe:STATIC_TYPE_ERROR*/o; |
| 874 nnn = /*warning:DownCastComposite*/n; | 876 nnn = /*warning:DOWN_CAST_COMPOSITE*/n; |
| 875 nnn = /*severe:StaticTypeError*/rr; | 877 nnn = /*severe:STATIC_TYPE_ERROR*/rr; |
| 876 nnn = /*severe:StaticTypeError*/ro; | 878 nnn = /*severe:STATIC_TYPE_ERROR*/ro; |
| 877 nnn = /*severe:StaticTypeError*/rn; | 879 nnn = /*severe:STATIC_TYPE_ERROR*/rn; |
| 878 nnn = /*severe:StaticTypeError*/oo; | 880 nnn = /*severe:STATIC_TYPE_ERROR*/oo; |
| 879 nnn = /*warning:DownCastComposite*/nn; | 881 nnn = /*warning:DOWN_CAST_COMPOSITE*/nn; |
| 880 nnn = nnn; | 882 nnn = nnn; |
| 881 } | 883 } |
| 882 ''' | 884 ''' |
| 883 }); | 885 }); |
| 884 | 886 |
| 885 testChecker('Function subtyping: objects with call methods', { | 887 testChecker('Function subtyping: objects with call methods', { |
| 886 '/main.dart': ''' | 888 '/main.dart': ''' |
| 887 | 889 |
| 888 typedef int I2I(int x); | 890 typedef int I2I(int x); |
| 889 typedef num N2N(num x); | 891 typedef num N2N(num x); |
| 890 class A { | 892 class A { |
| 891 int call(int x) => x; | 893 int call(int x) => x; |
| 892 } | 894 } |
| 893 class B { | 895 class B { |
| 894 num call(num x) => x; | 896 num call(num x) => x; |
| 895 } | 897 } |
| 896 int i2i(int x) => x; | 898 int i2i(int x) => x; |
| 897 num n2n(num x) => x; | 899 num n2n(num x) => x; |
| 898 void main() { | 900 void main() { |
| 899 { | 901 { |
| 900 I2I f; | 902 I2I f; |
| 901 f = new A(); | 903 f = new A(); |
| 902 f = /*severe:StaticTypeError*/new B(); | 904 f = /*severe:STATIC_TYPE_ERROR*/new B(); |
| 903 f = i2i; | 905 f = i2i; |
| 904 f = /*warning:DownCastComposite*/n2n; | 906 f = /*warning:DOWN_CAST_COMPOSITE*/n2n; |
| 905 f = /*warning:DownCastComposite*/i2i as Object; | 907 f = /*warning:DOWN_CAST_COMPOSITE*/i2i as Object; |
| 906 f = /*warning:DownCastComposite*/n2n as Function; | 908 f = /*warning:DOWN_CAST_COMPOSITE*/n2n as Function; |
| 907 } | 909 } |
| 908 { | 910 { |
| 909 N2N f; | 911 N2N f; |
| 910 f = /*severe:StaticTypeError*/new A(); | 912 f = /*severe:STATIC_TYPE_ERROR*/new A(); |
| 911 f = new B(); | 913 f = new B(); |
| 912 f = /*warning:DownCastComposite*/i2i; | 914 f = /*warning:DOWN_CAST_COMPOSITE*/i2i; |
| 913 f = n2n; | 915 f = n2n; |
| 914 f = /*warning:DownCastComposite*/i2i as Object; | 916 f = /*warning:DOWN_CAST_COMPOSITE*/i2i as Object; |
| 915 f = /*warning:DownCastComposite*/n2n as Function; | 917 f = /*warning:DOWN_CAST_COMPOSITE*/n2n as Function; |
| 916 } | 918 } |
| 917 { | 919 { |
| 918 A f; | 920 A f; |
| 919 f = new A(); | 921 f = new A(); |
| 920 f = /*severe:StaticTypeError*/new B(); | 922 f = /*severe:STATIC_TYPE_ERROR*/new B(); |
| 921 f = /*severe:StaticTypeError*/i2i; | 923 f = /*severe:STATIC_TYPE_ERROR*/i2i; |
| 922 f = /*severe:StaticTypeError*/n2n; | 924 f = /*severe:STATIC_TYPE_ERROR*/n2n; |
| 923 f = /*info:DownCastImplicit*/i2i as Object; | 925 f = /*info:DOWN_CAST_IMPLICIT*/i2i as Object; |
| 924 f = /*info:DownCastImplicit*/n2n as Function; | 926 f = /*info:DOWN_CAST_IMPLICIT*/n2n as Function; |
| 925 } | 927 } |
| 926 { | 928 { |
| 927 B f; | 929 B f; |
| 928 f = /*severe:StaticTypeError*/new A(); | 930 f = /*severe:STATIC_TYPE_ERROR*/new A(); |
| 929 f = new B(); | 931 f = new B(); |
| 930 f = /*severe:StaticTypeError*/i2i; | 932 f = /*severe:STATIC_TYPE_ERROR*/i2i; |
| 931 f = /*severe:StaticTypeError*/n2n; | 933 f = /*severe:STATIC_TYPE_ERROR*/n2n; |
| 932 f = /*info:DownCastImplicit*/i2i as Object; | 934 f = /*info:DOWN_CAST_IMPLICIT*/i2i as Object; |
| 933 f = /*info:DownCastImplicit*/n2n as Function; | 935 f = /*info:DOWN_CAST_IMPLICIT*/n2n as Function; |
| 934 } | 936 } |
| 935 { | 937 { |
| 936 Function f; | 938 Function f; |
| 937 f = new A(); | 939 f = new A(); |
| 938 f = new B(); | 940 f = new B(); |
| 939 f = i2i; | 941 f = i2i; |
| 940 f = n2n; | 942 f = n2n; |
| 941 f = /*info:DownCastImplicit*/i2i as Object; | 943 f = /*info:DOWN_CAST_IMPLICIT*/i2i as Object; |
| 942 f = (n2n as Function); | 944 f = (n2n as Function); |
| 943 } | 945 } |
| 944 } | 946 } |
| 945 ''' | 947 ''' |
| 946 }); | 948 }); |
| 947 | 949 |
| 948 testChecker('Function typing and subtyping: void', { | 950 testChecker('Function typing and subtyping: void', { |
| 949 '/main.dart': ''' | 951 '/main.dart': ''' |
| 950 | 952 |
| 951 class A { | 953 class A { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 990 } | 992 } |
| 991 { | 993 { |
| 992 lOfOs = mOfDs; | 994 lOfOs = mOfDs; |
| 993 lOfOs = mOfOs; | 995 lOfOs = mOfOs; |
| 994 lOfOs = mOfAs; | 996 lOfOs = mOfAs; |
| 995 lOfOs = lOfDs; | 997 lOfOs = lOfDs; |
| 996 lOfOs = lOfOs; | 998 lOfOs = lOfOs; |
| 997 lOfOs = lOfAs; | 999 lOfOs = lOfAs; |
| 998 } | 1000 } |
| 999 { | 1001 { |
| 1000 lOfAs = /*warning:DownCastComposite*/mOfDs; | 1002 lOfAs = /*warning:DOWN_CAST_COMPOSITE*/mOfDs; |
| 1001 lOfAs = /*severe:StaticTypeError*/mOfOs; | 1003 lOfAs = /*severe:STATIC_TYPE_ERROR*/mOfOs; |
| 1002 lOfAs = mOfAs; | 1004 lOfAs = mOfAs; |
| 1003 lOfAs = /*warning:DownCastComposite*/lOfDs; | 1005 lOfAs = /*warning:DOWN_CAST_COMPOSITE*/lOfDs; |
| 1004 lOfAs = /*info:DownCastImplicit*/lOfOs; | 1006 lOfAs = /*info:DOWN_CAST_IMPLICIT*/lOfOs; |
| 1005 lOfAs = lOfAs; | 1007 lOfAs = lOfAs; |
| 1006 } | 1008 } |
| 1007 { | 1009 { |
| 1008 mOfDs = mOfDs; | 1010 mOfDs = mOfDs; |
| 1009 mOfDs = mOfOs; | 1011 mOfDs = mOfOs; |
| 1010 mOfDs = mOfAs; | 1012 mOfDs = mOfAs; |
| 1011 mOfDs = /*info:DownCastImplicit*/lOfDs; | 1013 mOfDs = /*info:DOWN_CAST_IMPLICIT*/lOfDs; |
| 1012 mOfDs = /*info:DownCastImplicit*/lOfOs; | 1014 mOfDs = /*info:DOWN_CAST_IMPLICIT*/lOfOs; |
| 1013 mOfDs = /*warning:DownCastComposite*/lOfAs; | 1015 mOfDs = /*warning:DOWN_CAST_COMPOSITE*/lOfAs; |
| 1014 } | 1016 } |
| 1015 { | 1017 { |
| 1016 mOfOs = mOfDs; | 1018 mOfOs = mOfDs; |
| 1017 mOfOs = mOfOs; | 1019 mOfOs = mOfOs; |
| 1018 mOfOs = mOfAs; | 1020 mOfOs = mOfAs; |
| 1019 mOfOs = /*info:DownCastImplicit*/lOfDs; | 1021 mOfOs = /*info:DOWN_CAST_IMPLICIT*/lOfDs; |
| 1020 mOfOs = /*info:DownCastImplicit*/lOfOs; | 1022 mOfOs = /*info:DOWN_CAST_IMPLICIT*/lOfOs; |
| 1021 mOfOs = /*severe:StaticTypeError*/lOfAs; | 1023 mOfOs = /*severe:STATIC_TYPE_ERROR*/lOfAs; |
| 1022 } | 1024 } |
| 1023 { | 1025 { |
| 1024 mOfAs = /*warning:DownCastComposite*/mOfDs; | 1026 mOfAs = /*warning:DOWN_CAST_COMPOSITE*/mOfDs; |
| 1025 mOfAs = /*info:DownCastImplicit*/mOfOs; | 1027 mOfAs = /*info:DOWN_CAST_IMPLICIT*/mOfOs; |
| 1026 mOfAs = mOfAs; | 1028 mOfAs = mOfAs; |
| 1027 mOfAs = /*warning:DownCastComposite*/lOfDs; | 1029 mOfAs = /*warning:DOWN_CAST_COMPOSITE*/lOfDs; |
| 1028 mOfAs = /*info:DownCastImplicit*/lOfOs; | 1030 mOfAs = /*info:DOWN_CAST_IMPLICIT*/lOfOs; |
| 1029 mOfAs = /*info:DownCastImplicit*/lOfAs; | 1031 mOfAs = /*info:DOWN_CAST_IMPLICIT*/lOfAs; |
| 1030 } | 1032 } |
| 1031 | 1033 |
| 1032 } | 1034 } |
| 1033 ''' | 1035 ''' |
| 1034 }); | 1036 }); |
| 1035 | 1037 |
| 1036 testChecker('Type checking literals', { | 1038 testChecker('Type checking literals', { |
| 1037 '/main.dart': ''' | 1039 '/main.dart': ''' |
| 1038 test() { | 1040 test() { |
| 1039 num n = 3; | 1041 num n = 3; |
| 1040 int i = 3; | 1042 int i = 3; |
| 1041 String s = "hello"; | 1043 String s = "hello"; |
| 1042 { | 1044 { |
| 1043 List<int> l = <int>[i]; | 1045 List<int> l = <int>[i]; |
| 1044 l = <int>[/*severe:StaticTypeError*/s]; | 1046 l = <int>[/*severe:STATIC_TYPE_ERROR*/s]; |
| 1045 l = <int>[/*info:DownCastImplicit*/n]; | 1047 l = <int>[/*info:DOWN_CAST_IMPLICIT*/n]; |
| 1046 l = <int>[i, /*info:DownCastImplicit*/n, /*severe:StaticTypeError
*/s]; | 1048 l = <int>[i, /*info:DOWN_CAST_IMPLICIT*/n, /*severe:STATIC_TYPE_E
RROR*/s]; |
| 1047 } | 1049 } |
| 1048 { | 1050 { |
| 1049 List l = [i]; | 1051 List l = [i]; |
| 1050 l = [s]; | 1052 l = [s]; |
| 1051 l = [n]; | 1053 l = [n]; |
| 1052 l = [i, n, s]; | 1054 l = [i, n, s]; |
| 1053 } | 1055 } |
| 1054 { | 1056 { |
| 1055 Map<String, int> m = <String, int>{s: i}; | 1057 Map<String, int> m = <String, int>{s: i}; |
| 1056 m = <String, int>{s: /*severe:StaticTypeError*/s}; | 1058 m = <String, int>{s: /*severe:STATIC_TYPE_ERROR*/s}; |
| 1057 m = <String, int>{s: /*info:DownCastImplicit*/n}; | 1059 m = <String, int>{s: /*info:DOWN_CAST_IMPLICIT*/n}; |
| 1058 m = <String, int>{s: i, | 1060 m = <String, int>{s: i, |
| 1059 s: /*info:DownCastImplicit*/n, | 1061 s: /*info:DOWN_CAST_IMPLICIT*/n, |
| 1060 s: /*severe:StaticTypeError*/s}; | 1062 s: /*severe:STATIC_TYPE_ERROR*/s}; |
| 1061 } | 1063 } |
| 1062 // TODO(leafp): We can't currently test for key errors since the | 1064 // TODO(leafp): We can't currently test for key errors since the |
| 1063 // error marker binds to the entire entry. | 1065 // error marker binds to the entire entry. |
| 1064 { | 1066 { |
| 1065 Map m = {s: i}; | 1067 Map m = {s: i}; |
| 1066 m = {s: s}; | 1068 m = {s: s}; |
| 1067 m = {s: n}; | 1069 m = {s: n}; |
| 1068 m = {s: i, | 1070 m = {s: i, |
| 1069 s: n, | 1071 s: n, |
| 1070 s: s}; | 1072 s: s}; |
| 1071 m = {i: s, | 1073 m = {i: s, |
| 1072 n: s, | 1074 n: s, |
| 1073 s: s}; | 1075 s: s}; |
| 1074 } | 1076 } |
| 1075 } | 1077 } |
| 1076 ''' | 1078 ''' |
| 1077 }); | 1079 }); |
| 1078 | 1080 |
| 1079 testChecker('casts in constant contexts', { | 1081 testChecker('casts in constant contexts', { |
| 1080 '/main.dart': ''' | 1082 '/main.dart': ''' |
| 1081 class A { | 1083 class A { |
| 1082 static const num n = 3.0; | 1084 static const num n = 3.0; |
| 1083 static const int i = /*info:AssignmentCast*/n; | 1085 static const int i = /*info:ASSIGNMENT_CAST*/n; |
| 1084 final int fi; | 1086 final int fi; |
| 1085 const A(num a) : this.fi = /*info:DownCastImplicit*/a; | 1087 const A(num a) : this.fi = /*info:DOWN_CAST_IMPLICIT*/a; |
| 1086 } | 1088 } |
| 1087 class B extends A { | 1089 class B extends A { |
| 1088 const B(Object a) : super(/*info:DownCastImplicit*/a); | 1090 const B(Object a) : super(/*info:DOWN_CAST_IMPLICIT*/a); |
| 1089 } | 1091 } |
| 1090 void foo(Object o) { | 1092 void foo(Object o) { |
| 1091 var a = const A(/*info:DownCastImplicit*/o); | 1093 var a = const A(/*info:DOWN_CAST_IMPLICIT*/o); |
| 1092 } | 1094 } |
| 1093 ''' | 1095 ''' |
| 1094 }); | 1096 }); |
| 1095 | 1097 |
| 1096 testChecker('casts in conditionals', { | 1098 testChecker('casts in conditionals', { |
| 1097 '/main.dart': ''' | 1099 '/main.dart': ''' |
| 1098 main() { | 1100 main() { |
| 1099 bool b = true; | 1101 bool b = true; |
| 1100 num x = b ? 1 : 2.3; | 1102 num x = b ? 1 : 2.3; |
| 1101 int y = /*info:AssignmentCast*/b ? 1 : 2.3; | 1103 int y = /*info:ASSIGNMENT_CAST*/b ? 1 : 2.3; |
| 1102 String z = !b ? "hello" : null; | 1104 String z = !b ? "hello" : null; |
| 1103 z = b ? null : "hello"; | 1105 z = b ? null : "hello"; |
| 1104 } | 1106 } |
| 1105 ''' | 1107 ''' |
| 1106 }); | 1108 }); |
| 1107 | 1109 |
| 1108 testChecker('redirecting constructor', { | 1110 testChecker('redirecting constructor', { |
| 1109 '/main.dart': ''' | 1111 '/main.dart': ''' |
| 1110 class A { | 1112 class A { |
| 1111 A(A x) {} | 1113 A(A x) {} |
| 1112 A.two() : this(/*severe:StaticTypeError*/3); | 1114 A.two() : this(/*severe:STATIC_TYPE_ERROR*/3); |
| 1113 } | 1115 } |
| 1114 ''' | 1116 ''' |
| 1115 }); | 1117 }); |
| 1116 | 1118 |
| 1117 testChecker('super constructor', { | 1119 testChecker('super constructor', { |
| 1118 '/main.dart': ''' | 1120 '/main.dart': ''' |
| 1119 class A { A(A x) {} } | 1121 class A { A(A x) {} } |
| 1120 class B extends A { | 1122 class B extends A { |
| 1121 B() : super(/*severe:StaticTypeError*/3); | 1123 B() : super(/*severe:STATIC_TYPE_ERROR*/3); |
| 1122 } | 1124 } |
| 1123 ''' | 1125 ''' |
| 1124 }); | 1126 }); |
| 1125 | 1127 |
| 1126 testChecker('field/field override', { | 1128 testChecker('field/field override', { |
| 1127 '/main.dart': ''' | 1129 '/main.dart': ''' |
| 1128 class A {} | 1130 class A {} |
| 1129 class B extends A {} | 1131 class B extends A {} |
| 1130 class C extends B {} | 1132 class C extends B {} |
| 1131 | 1133 |
| 1132 class Base { | 1134 class Base { |
| 1133 B f1; | 1135 B f1; |
| 1134 B f2; | 1136 B f2; |
| 1135 B f3; | 1137 B f3; |
| 1136 B f4; | 1138 B f4; |
| 1137 } | 1139 } |
| 1138 | 1140 |
| 1139 class Child extends Base { | 1141 class Child extends Base { |
| 1140 /*severe:InvalidFieldOverride,severe:InvalidMethodOverride*/A f1; //
invalid for getter | 1142 /*severe:INVALID_FIELD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE*/A f1
; // invalid for getter |
| 1141 /*severe:InvalidFieldOverride,severe:InvalidMethodOverride*/C f2; //
invalid for setter | 1143 /*severe:INVALID_FIELD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE*/C f2
; // invalid for setter |
| 1142 /*severe:InvalidFieldOverride*/var f3; | 1144 /*severe:INVALID_FIELD_OVERRIDE*/var f3; |
| 1143 /*severe:InvalidFieldOverride,severe:InvalidMethodOverride,severe:In
validMethodOverride*/dynamic f4; | 1145 /*severe:INVALID_FIELD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE,sever
e:INVALID_METHOD_OVERRIDE*/dynamic f4; |
| 1144 } | 1146 } |
| 1145 | 1147 |
| 1146 class Child2 implements Base { | 1148 class Child2 implements Base { |
| 1147 /*severe:InvalidMethodOverride*/A f1; // invalid for getter | 1149 /*severe:INVALID_METHOD_OVERRIDE*/A f1; // invalid for getter |
| 1148 /*severe:InvalidMethodOverride*/C f2; // invalid for setter | 1150 /*severe:INVALID_METHOD_OVERRIDE*/C f2; // invalid for setter |
| 1149 var f3; | 1151 var f3; |
| 1150 /*severe:InvalidMethodOverride,severe:InvalidMethodOverride*/dynamic
f4; | 1152 /*severe:INVALID_METHOD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE*/dyn
amic f4; |
| 1151 } | 1153 } |
| 1152 ''' | 1154 ''' |
| 1153 }); | 1155 }); |
| 1154 | 1156 |
| 1155 testChecker('private override', { | 1157 testChecker('private override', { |
| 1156 '/helper.dart': ''' | 1158 '/helper.dart': ''' |
| 1157 import 'main.dart' as main; | 1159 import 'main.dart' as main; |
| 1158 | 1160 |
| 1159 class Base { | 1161 class Base { |
| 1160 var f1; | 1162 var f1; |
| 1161 var _f2; | 1163 var _f2; |
| 1162 var _f3; | 1164 var _f3; |
| 1163 get _f4 => null; | 1165 get _f4 => null; |
| 1164 | 1166 |
| 1165 int _m1(); | 1167 int _m1(); |
| 1166 } | 1168 } |
| 1167 | 1169 |
| 1168 class GrandChild extends main.Child { | 1170 class GrandChild extends main.Child { |
| 1169 /*severe:InvalidFieldOverride*/var _f2; | 1171 /*severe:INVALID_FIELD_OVERRIDE*/var _f2; |
| 1170 /*severe:InvalidFieldOverride*/var _f3; | 1172 /*severe:INVALID_FIELD_OVERRIDE*/var _f3; |
| 1171 var _f4; | 1173 var _f4; |
| 1172 | 1174 |
| 1173 /*severe:InvalidMethodOverride*/String _m1(); | 1175 /*severe:INVALID_METHOD_OVERRIDE*/String _m1(); |
| 1174 } | 1176 } |
| 1175 ''', | 1177 ''', |
| 1176 '/main.dart': ''' | 1178 '/main.dart': ''' |
| 1177 import 'helper.dart' as helper; | 1179 import 'helper.dart' as helper; |
| 1178 | 1180 |
| 1179 class Child extends helper.Base { | 1181 class Child extends helper.Base { |
| 1180 /*severe:InvalidFieldOverride*/var f1; | 1182 /*severe:INVALID_FIELD_OVERRIDE*/var f1; |
| 1181 var _f2; | 1183 var _f2; |
| 1182 var _f4; | 1184 var _f4; |
| 1183 | 1185 |
| 1184 String _m1(); | 1186 String _m1(); |
| 1185 } | 1187 } |
| 1186 ''' | 1188 ''' |
| 1187 }); | 1189 }); |
| 1188 | 1190 |
| 1189 testChecker('getter/getter override', { | 1191 testChecker('getter/getter override', { |
| 1190 '/main.dart': ''' | 1192 '/main.dart': ''' |
| 1191 class A {} | 1193 class A {} |
| 1192 class B extends A {} | 1194 class B extends A {} |
| 1193 class C extends B {} | 1195 class C extends B {} |
| 1194 | 1196 |
| 1195 abstract class Base { | 1197 abstract class Base { |
| 1196 B get f1; | 1198 B get f1; |
| 1197 B get f2; | 1199 B get f2; |
| 1198 B get f3; | 1200 B get f3; |
| 1199 B get f4; | 1201 B get f4; |
| 1200 } | 1202 } |
| 1201 | 1203 |
| 1202 class Child extends Base { | 1204 class Child extends Base { |
| 1203 /*severe:InvalidMethodOverride*/A get f1 => null; | 1205 /*severe:INVALID_METHOD_OVERRIDE*/A get f1 => null; |
| 1204 C get f2 => null; | 1206 C get f2 => null; |
| 1205 get f3 => null; | 1207 get f3 => null; |
| 1206 /*severe:InvalidMethodOverride*/dynamic get f4 => null; | 1208 /*severe:INVALID_METHOD_OVERRIDE*/dynamic get f4 => null; |
| 1207 } | 1209 } |
| 1208 ''' | 1210 ''' |
| 1209 }); | 1211 }); |
| 1210 | 1212 |
| 1211 testChecker('field/getter override', { | 1213 testChecker('field/getter override', { |
| 1212 '/main.dart': ''' | 1214 '/main.dart': ''' |
| 1213 class A {} | 1215 class A {} |
| 1214 class B extends A {} | 1216 class B extends A {} |
| 1215 class C extends B {} | 1217 class C extends B {} |
| 1216 | 1218 |
| 1217 abstract class Base { | 1219 abstract class Base { |
| 1218 B f1; | 1220 B f1; |
| 1219 B f2; | 1221 B f2; |
| 1220 B f3; | 1222 B f3; |
| 1221 B f4; | 1223 B f4; |
| 1222 } | 1224 } |
| 1223 | 1225 |
| 1224 class Child extends Base { | 1226 class Child extends Base { |
| 1225 /*severe:InvalidFieldOverride,severe:InvalidMethodOverride*/A get f1
=> null; | 1227 /*severe:INVALID_FIELD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE*/A ge
t f1 => null; |
| 1226 /*severe:InvalidFieldOverride*/C get f2 => null; | 1228 /*severe:INVALID_FIELD_OVERRIDE*/C get f2 => null; |
| 1227 /*severe:InvalidFieldOverride*/get f3 => null; | 1229 /*severe:INVALID_FIELD_OVERRIDE*/get f3 => null; |
| 1228 /*severe:InvalidFieldOverride,severe:InvalidMethodOverride*/dynamic
get f4 => null; | 1230 /*severe:INVALID_FIELD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE*/dyna
mic get f4 => null; |
| 1229 } | 1231 } |
| 1230 | 1232 |
| 1231 class Child2 implements Base { | 1233 class Child2 implements Base { |
| 1232 /*severe:InvalidMethodOverride*/A get f1 => null; | 1234 /*severe:INVALID_METHOD_OVERRIDE*/A get f1 => null; |
| 1233 C get f2 => null; | 1235 C get f2 => null; |
| 1234 get f3 => null; | 1236 get f3 => null; |
| 1235 /*severe:InvalidMethodOverride*/dynamic get f4 => null; | 1237 /*severe:INVALID_METHOD_OVERRIDE*/dynamic get f4 => null; |
| 1236 } | 1238 } |
| 1237 ''' | 1239 ''' |
| 1238 }); | 1240 }); |
| 1239 | 1241 |
| 1240 testChecker('setter/setter override', { | 1242 testChecker('setter/setter override', { |
| 1241 '/main.dart': ''' | 1243 '/main.dart': ''' |
| 1242 class A {} | 1244 class A {} |
| 1243 class B extends A {} | 1245 class B extends A {} |
| 1244 class C extends B {} | 1246 class C extends B {} |
| 1245 | 1247 |
| 1246 abstract class Base { | 1248 abstract class Base { |
| 1247 void set f1(B value); | 1249 void set f1(B value); |
| 1248 void set f2(B value); | 1250 void set f2(B value); |
| 1249 void set f3(B value); | 1251 void set f3(B value); |
| 1250 void set f4(B value); | 1252 void set f4(B value); |
| 1251 void set f5(B value); | 1253 void set f5(B value); |
| 1252 } | 1254 } |
| 1253 | 1255 |
| 1254 class Child extends Base { | 1256 class Child extends Base { |
| 1255 void set f1(A value) {} | 1257 void set f1(A value) {} |
| 1256 /*severe:InvalidMethodOverride*/void set f2(C value) {} | 1258 /*severe:INVALID_METHOD_OVERRIDE*/void set f2(C value) {} |
| 1257 void set f3(value) {} | 1259 void set f3(value) {} |
| 1258 /*severe:InvalidMethodOverride*/void set f4(dynamic value) {} | 1260 /*severe:INVALID_METHOD_OVERRIDE*/void set f4(dynamic value) {} |
| 1259 set f5(B value) {} | 1261 set f5(B value) {} |
| 1260 } | 1262 } |
| 1261 ''' | 1263 ''' |
| 1262 }); | 1264 }); |
| 1263 | 1265 |
| 1264 testChecker('field/setter override', { | 1266 testChecker('field/setter override', { |
| 1265 '/main.dart': ''' | 1267 '/main.dart': ''' |
| 1266 class A {} | 1268 class A {} |
| 1267 class B extends A {} | 1269 class B extends A {} |
| 1268 class C extends B {} | 1270 class C extends B {} |
| 1269 | 1271 |
| 1270 class Base { | 1272 class Base { |
| 1271 B f1; | 1273 B f1; |
| 1272 B f2; | 1274 B f2; |
| 1273 B f3; | 1275 B f3; |
| 1274 B f4; | 1276 B f4; |
| 1275 B f5; | 1277 B f5; |
| 1276 } | 1278 } |
| 1277 | 1279 |
| 1278 class Child extends Base { | 1280 class Child extends Base { |
| 1279 /*severe:InvalidFieldOverride*/B get f1 => null; | 1281 /*severe:INVALID_FIELD_OVERRIDE*/B get f1 => null; |
| 1280 /*severe:InvalidFieldOverride*/B get f2 => null; | 1282 /*severe:INVALID_FIELD_OVERRIDE*/B get f2 => null; |
| 1281 /*severe:InvalidFieldOverride*/B get f3 => null; | 1283 /*severe:INVALID_FIELD_OVERRIDE*/B get f3 => null; |
| 1282 /*severe:InvalidFieldOverride*/B get f4 => null; | 1284 /*severe:INVALID_FIELD_OVERRIDE*/B get f4 => null; |
| 1283 /*severe:InvalidFieldOverride*/B get f5 => null; | 1285 /*severe:INVALID_FIELD_OVERRIDE*/B get f5 => null; |
| 1284 | 1286 |
| 1285 /*severe:InvalidFieldOverride*/void set f1(A value) {} | 1287 /*severe:INVALID_FIELD_OVERRIDE*/void set f1(A value) {} |
| 1286 /*severe:InvalidFieldOverride,severe:InvalidMethodOverride*/void set
f2(C value) {} | 1288 /*severe:INVALID_FIELD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE*/void
set f2(C value) {} |
| 1287 /*severe:InvalidFieldOverride*/void set f3(value) {} | 1289 /*severe:INVALID_FIELD_OVERRIDE*/void set f3(value) {} |
| 1288 /*severe:InvalidFieldOverride,severe:InvalidMethodOverride*/void set
f4(dynamic value) {} | 1290 /*severe:INVALID_FIELD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE*/void
set f4(dynamic value) {} |
| 1289 /*severe:InvalidFieldOverride*/set f5(B value) {} | 1291 /*severe:INVALID_FIELD_OVERRIDE*/set f5(B value) {} |
| 1290 } | 1292 } |
| 1291 | 1293 |
| 1292 class Child2 implements Base { | 1294 class Child2 implements Base { |
| 1293 B get f1 => null; | 1295 B get f1 => null; |
| 1294 B get f2 => null; | 1296 B get f2 => null; |
| 1295 B get f3 => null; | 1297 B get f3 => null; |
| 1296 B get f4 => null; | 1298 B get f4 => null; |
| 1297 B get f5 => null; | 1299 B get f5 => null; |
| 1298 | 1300 |
| 1299 void set f1(A value) {} | 1301 void set f1(A value) {} |
| 1300 /*severe:InvalidMethodOverride*/void set f2(C value) {} | 1302 /*severe:INVALID_METHOD_OVERRIDE*/void set f2(C value) {} |
| 1301 void set f3(value) {} | 1303 void set f3(value) {} |
| 1302 /*severe:InvalidMethodOverride*/void set f4(dynamic value) {} | 1304 /*severe:INVALID_METHOD_OVERRIDE*/void set f4(dynamic value) {} |
| 1303 set f5(B value) {} | 1305 set f5(B value) {} |
| 1304 } | 1306 } |
| 1305 ''' | 1307 ''' |
| 1306 }); | 1308 }); |
| 1307 | 1309 |
| 1308 testChecker('method override', { | 1310 testChecker('method override', { |
| 1309 '/main.dart': ''' | 1311 '/main.dart': ''' |
| 1310 class A {} | 1312 class A {} |
| 1311 class B extends A {} | 1313 class B extends A {} |
| 1312 class C extends B {} | 1314 class C extends B {} |
| 1313 | 1315 |
| 1314 class Base { | 1316 class Base { |
| 1315 B m1(B a); | 1317 B m1(B a); |
| 1316 B m2(B a); | 1318 B m2(B a); |
| 1317 B m3(B a); | 1319 B m3(B a); |
| 1318 B m4(B a); | 1320 B m4(B a); |
| 1319 B m5(B a); | 1321 B m5(B a); |
| 1320 B m6(B a); | 1322 B m6(B a); |
| 1321 } | 1323 } |
| 1322 | 1324 |
| 1323 class Child extends Base { | 1325 class Child extends Base { |
| 1324 /*severe:InvalidMethodOverride*/A m1(A value) {} | 1326 /*severe:INVALID_METHOD_OVERRIDE*/A m1(A value) {} |
| 1325 /*severe:InvalidMethodOverride*/C m2(C value) {} | 1327 /*severe:INVALID_METHOD_OVERRIDE*/C m2(C value) {} |
| 1326 /*severe:InvalidMethodOverride*/A m3(C value) {} | 1328 /*severe:INVALID_METHOD_OVERRIDE*/A m3(C value) {} |
| 1327 C m4(A value) {} | 1329 C m4(A value) {} |
| 1328 m5(value) {} | 1330 m5(value) {} |
| 1329 /*severe:InvalidMethodOverride*/dynamic m6(dynamic value) {} | 1331 /*severe:INVALID_METHOD_OVERRIDE*/dynamic m6(dynamic value) {} |
| 1330 } | 1332 } |
| 1331 ''' | 1333 ''' |
| 1332 }); | 1334 }); |
| 1333 | 1335 |
| 1334 testChecker('unary operators', { | 1336 testChecker('unary operators', { |
| 1335 '/main.dart': ''' | 1337 '/main.dart': ''' |
| 1336 class A { | 1338 class A { |
| 1337 A operator ~() {} | 1339 A operator ~() {} |
| 1338 A operator +(int x) {} | 1340 A operator +(int x) {} |
| 1339 A operator -(int x) {} | 1341 A operator -(int x) {} |
| 1340 A operator -() {} | 1342 A operator -() {} |
| 1341 } | 1343 } |
| 1342 | 1344 |
| 1343 foo() => new A(); | 1345 foo() => new A(); |
| 1344 | 1346 |
| 1345 test() { | 1347 test() { |
| 1346 A a = new A(); | 1348 A a = new A(); |
| 1347 var c = foo(); | 1349 var c = foo(); |
| 1348 | 1350 |
| 1349 ~a; | 1351 ~a; |
| 1350 (/*info:DynamicInvoke*/~d); | 1352 (/*info:DYNAMIC_INVOKE*/~d); |
| 1351 | 1353 |
| 1352 !/*severe:StaticTypeError*/a; | 1354 !/*severe:STATIC_TYPE_ERROR*/a; |
| 1353 !/*info:DynamicCast*/d; | 1355 !/*info:DYNAMIC_CAST*/d; |
| 1354 | 1356 |
| 1355 -a; | 1357 -a; |
| 1356 (/*info:DynamicInvoke*/-d); | 1358 (/*info:DYNAMIC_INVOKE*/-d); |
| 1357 | 1359 |
| 1358 ++a; | 1360 ++a; |
| 1359 --a; | 1361 --a; |
| 1360 (/*info:DynamicInvoke*/++d); | 1362 (/*info:DYNAMIC_INVOKE*/++d); |
| 1361 (/*info:DynamicInvoke*/--d); | 1363 (/*info:DYNAMIC_INVOKE*/--d); |
| 1362 | 1364 |
| 1363 a++; | 1365 a++; |
| 1364 a--; | 1366 a--; |
| 1365 (/*info:DynamicInvoke*/d++); | 1367 (/*info:DYNAMIC_INVOKE*/d++); |
| 1366 (/*info:DynamicInvoke*/d--); | 1368 (/*info:DYNAMIC_INVOKE*/d--); |
| 1367 }''' | 1369 }''' |
| 1368 }); | 1370 }); |
| 1369 | 1371 |
| 1370 testChecker('binary and index operators', { | 1372 testChecker('binary and index operators', { |
| 1371 '/main.dart': ''' | 1373 '/main.dart': ''' |
| 1372 class A { | 1374 class A { |
| 1373 A operator *(B b) {} | 1375 A operator *(B b) {} |
| 1374 A operator /(B b) {} | 1376 A operator /(B b) {} |
| 1375 A operator ~/(B b) {} | 1377 A operator ~/(B b) {} |
| 1376 A operator %(B b) {} | 1378 A operator %(B b) {} |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1388 A operator -(B b) {} | 1390 A operator -(B b) {} |
| 1389 } | 1391 } |
| 1390 | 1392 |
| 1391 foo() => new A(); | 1393 foo() => new A(); |
| 1392 | 1394 |
| 1393 test() { | 1395 test() { |
| 1394 A a = new A(); | 1396 A a = new A(); |
| 1395 B b = new B(); | 1397 B b = new B(); |
| 1396 var c = foo(); | 1398 var c = foo(); |
| 1397 a = a * b; | 1399 a = a * b; |
| 1398 a = a * /*info:DynamicCast*/c; | 1400 a = a * /*info:DYNAMIC_CAST*/c; |
| 1399 a = a / b; | 1401 a = a / b; |
| 1400 a = a ~/ b; | 1402 a = a ~/ b; |
| 1401 a = a % b; | 1403 a = a % b; |
| 1402 a = a + b; | 1404 a = a + b; |
| 1403 a = a + /*severe:StaticTypeError*/a; | 1405 a = a + /*severe:STATIC_TYPE_ERROR*/a; |
| 1404 a = a - b; | 1406 a = a - b; |
| 1405 b = /*severe:StaticTypeError*/b - b; | 1407 b = /*severe:STATIC_TYPE_ERROR*/b - b; |
| 1406 a = a << b; | 1408 a = a << b; |
| 1407 a = a >> b; | 1409 a = a >> b; |
| 1408 a = a & b; | 1410 a = a & b; |
| 1409 a = a ^ b; | 1411 a = a ^ b; |
| 1410 a = a | b; | 1412 a = a | b; |
| 1411 c = (/*info:DynamicInvoke*/c + b); | 1413 c = (/*info:DYNAMIC_INVOKE*/c + b); |
| 1412 | 1414 |
| 1413 String x = 'hello'; | 1415 String x = 'hello'; |
| 1414 int y = 42; | 1416 int y = 42; |
| 1415 x = x + x; | 1417 x = x + x; |
| 1416 x = x + /*info:DynamicCast*/c; | 1418 x = x + /*info:DYNAMIC_CAST*/c; |
| 1417 x = x + /*severe:StaticTypeError*/y; | 1419 x = x + /*severe:STATIC_TYPE_ERROR*/y; |
| 1418 | 1420 |
| 1419 bool p = true; | 1421 bool p = true; |
| 1420 p = p && p; | 1422 p = p && p; |
| 1421 p = p && /*info:DynamicCast*/c; | 1423 p = p && /*info:DYNAMIC_CAST*/c; |
| 1422 p = (/*info:DynamicCast*/c) && p; | 1424 p = (/*info:DYNAMIC_CAST*/c) && p; |
| 1423 p = (/*info:DynamicCast*/c) && /*info:DynamicCast*/c; | 1425 p = (/*info:DYNAMIC_CAST*/c) && /*info:DYNAMIC_CAST*/c; |
| 1424 p = (/*severe:StaticTypeError*/y) && p; | 1426 p = (/*severe:STATIC_TYPE_ERROR*/y) && p; |
| 1425 p = c == y; | 1427 p = c == y; |
| 1426 | 1428 |
| 1427 a = a[b]; | 1429 a = a[b]; |
| 1428 a = a[/*info:DynamicCast*/c]; | 1430 a = a[/*info:DYNAMIC_CAST*/c]; |
| 1429 c = (/*info:DynamicInvoke*/c[b]); | 1431 c = (/*info:DYNAMIC_INVOKE*/c[b]); |
| 1430 a[/*severe:StaticTypeError*/y]; | 1432 a[/*severe:STATIC_TYPE_ERROR*/y]; |
| 1431 } | 1433 } |
| 1432 ''' | 1434 ''' |
| 1433 }); | 1435 }); |
| 1434 | 1436 |
| 1435 testChecker('compound assignments', { | 1437 testChecker('compound assignments', { |
| 1436 '/main.dart': ''' | 1438 '/main.dart': ''' |
| 1437 class A { | 1439 class A { |
| 1438 A operator *(B b) {} | 1440 A operator *(B b) {} |
| 1439 A operator /(B b) {} | 1441 A operator /(B b) {} |
| 1440 A operator ~/(B b) {} | 1442 A operator ~/(B b) {} |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1456 | 1458 |
| 1457 class D { | 1459 class D { |
| 1458 D operator +(D d) {} | 1460 D operator +(D d) {} |
| 1459 } | 1461 } |
| 1460 | 1462 |
| 1461 foo() => new A(); | 1463 foo() => new A(); |
| 1462 | 1464 |
| 1463 test() { | 1465 test() { |
| 1464 int x = 0; | 1466 int x = 0; |
| 1465 x += 5; | 1467 x += 5; |
| 1466 (/*severe:StaticTypeError*/x += 3.14); | 1468 (/*severe:STATIC_TYPE_ERROR*/x += 3.14); |
| 1467 | 1469 |
| 1468 double y = 0.0; | 1470 double y = 0.0; |
| 1469 y += 5; | 1471 y += 5; |
| 1470 y += 3.14; | 1472 y += 3.14; |
| 1471 | 1473 |
| 1472 num z = 0; | 1474 num z = 0; |
| 1473 z += 5; | 1475 z += 5; |
| 1474 z += 3.14; | 1476 z += 3.14; |
| 1475 | 1477 |
| 1476 x = /*info:DownCastImplicit*/x + z; | 1478 x = /*info:DOWN_CAST_IMPLICIT*/x + z; |
| 1477 x += /*info:DownCastImplicit*/z; | 1479 x += /*info:DOWN_CAST_IMPLICIT*/z; |
| 1478 y = /*info:DownCastImplicit*/y + z; | 1480 y = /*info:DOWN_CAST_IMPLICIT*/y + z; |
| 1479 y += /*info:DownCastImplicit*/z; | 1481 y += /*info:DOWN_CAST_IMPLICIT*/z; |
| 1480 | 1482 |
| 1481 dynamic w = 42; | 1483 dynamic w = 42; |
| 1482 x += /*info:DynamicCast*/w; | 1484 x += /*info:DYNAMIC_CAST*/w; |
| 1483 y += /*info:DynamicCast*/w; | 1485 y += /*info:DYNAMIC_CAST*/w; |
| 1484 z += /*info:DynamicCast*/w; | 1486 z += /*info:DYNAMIC_CAST*/w; |
| 1485 | 1487 |
| 1486 A a = new A(); | 1488 A a = new A(); |
| 1487 B b = new B(); | 1489 B b = new B(); |
| 1488 var c = foo(); | 1490 var c = foo(); |
| 1489 a = a * b; | 1491 a = a * b; |
| 1490 a *= b; | 1492 a *= b; |
| 1491 a *= /*info:DynamicCast*/c; | 1493 a *= /*info:DYNAMIC_CAST*/c; |
| 1492 a /= b; | 1494 a /= b; |
| 1493 a ~/= b; | 1495 a ~/= b; |
| 1494 a %= b; | 1496 a %= b; |
| 1495 a += b; | 1497 a += b; |
| 1496 a += /*severe:StaticTypeError*/a; | 1498 a += /*severe:STATIC_TYPE_ERROR*/a; |
| 1497 a -= b; | 1499 a -= b; |
| 1498 (/*severe:StaticTypeError*/b -= b); | 1500 (/*severe:STATIC_TYPE_ERROR*/b -= b); |
| 1499 a <<= b; | 1501 a <<= b; |
| 1500 a >>= b; | 1502 a >>= b; |
| 1501 a &= b; | 1503 a &= b; |
| 1502 a ^= b; | 1504 a ^= b; |
| 1503 a |= b; | 1505 a |= b; |
| 1504 (/*info:DynamicInvoke*/c += b); | 1506 (/*info:DYNAMIC_INVOKE*/c += b); |
| 1505 | 1507 |
| 1506 var d = new D(); | 1508 var d = new D(); |
| 1507 a[b] += d; | 1509 a[b] += d; |
| 1508 a[/*info:DynamicCast*/c] += d; | 1510 a[/*info:DYNAMIC_CAST*/c] += d; |
| 1509 a[/*severe:StaticTypeError*/z] += d; | 1511 a[/*severe:STATIC_TYPE_ERROR*/z] += d; |
| 1510 a[b] += /*info:DynamicCast*/c; | 1512 a[b] += /*info:DYNAMIC_CAST*/c; |
| 1511 a[b] += /*severe:StaticTypeError*/z; | 1513 a[b] += /*severe:STATIC_TYPE_ERROR*/z; |
| 1512 (/*info:DynamicInvoke*/(/*info:DynamicInvoke*/c[b]) += d); | 1514 (/*info:DYNAMIC_INVOKE*/(/*info:DYNAMIC_INVOKE*/c[b]) += d); |
| 1513 } | 1515 } |
| 1514 ''' | 1516 ''' |
| 1515 }); | 1517 }); |
| 1516 | 1518 |
| 1517 testChecker('super call placement', { | 1519 testChecker('super call placement', { |
| 1518 '/main.dart': ''' | 1520 '/main.dart': ''' |
| 1519 class Base { | 1521 class Base { |
| 1520 var x; | 1522 var x; |
| 1521 Base() : x = print('Base.1') { print('Base.2'); } | 1523 Base() : x = print('Base.1') { print('Base.2'); } |
| 1522 } | 1524 } |
| 1523 | 1525 |
| 1524 class Derived extends Base { | 1526 class Derived extends Base { |
| 1525 var y, z; | 1527 var y, z; |
| 1526 Derived() | 1528 Derived() |
| 1527 : y = print('Derived.1'), | 1529 : y = print('Derived.1'), |
| 1528 /*severe:InvalidSuperInvocation*/super(), | 1530 /*severe:INVALID_SUPER_INVOCATION*/super(), |
| 1529 z = print('Derived.2') { | 1531 z = print('Derived.2') { |
| 1530 print('Derived.3'); | 1532 print('Derived.3'); |
| 1531 } | 1533 } |
| 1532 } | 1534 } |
| 1533 | 1535 |
| 1534 class Valid extends Base { | 1536 class Valid extends Base { |
| 1535 var y, z; | 1537 var y, z; |
| 1536 Valid() | 1538 Valid() |
| 1537 : y = print('Valid.1'), | 1539 : y = print('Valid.1'), |
| 1538 z = print('Valid.2'), | 1540 z = print('Valid.2'), |
| 1539 super() { | 1541 super() { |
| 1540 print('Valid.3'); | 1542 print('Valid.3'); |
| 1541 } | 1543 } |
| 1542 } | 1544 } |
| 1543 | 1545 |
| 1544 class AlsoValid extends Base { | 1546 class AlsoValid extends Base { |
| 1545 AlsoValid() : super(); | 1547 AlsoValid() : super(); |
| 1546 } | 1548 } |
| 1547 | 1549 |
| 1548 main() => new Derived(); | 1550 main() => new Derived(); |
| 1549 ''' | 1551 ''' |
| 1550 }); | 1552 }); |
| 1551 | 1553 |
| 1552 testChecker('for loop variable', { | 1554 testChecker('for loop variable', { |
| 1553 '/main.dart': ''' | 1555 '/main.dart': ''' |
| 1554 foo() { | 1556 foo() { |
| 1555 for (int i = 0; i < 10; i++) { | 1557 for (int i = 0; i < 10; i++) { |
| 1556 i = /*severe:StaticTypeError*/"hi"; | 1558 i = /*severe:STATIC_TYPE_ERROR*/"hi"; |
| 1557 } | 1559 } |
| 1558 } | 1560 } |
| 1559 bar() { | 1561 bar() { |
| 1560 for (var i = 0; i < 10; i++) { | 1562 for (var i = 0; i < 10; i++) { |
| 1561 int j = i + 1; | 1563 int j = i + 1; |
| 1562 } | 1564 } |
| 1563 } | 1565 } |
| 1564 ''' | 1566 ''' |
| 1565 }); | 1567 }); |
| 1566 | 1568 |
| 1567 group('invalid overrides', () { | 1569 group('invalid overrides', () { |
| 1568 testChecker('child override', { | 1570 testChecker('child override', { |
| 1569 '/main.dart': ''' | 1571 '/main.dart': ''' |
| 1570 class A {} | 1572 class A {} |
| 1571 class B {} | 1573 class B {} |
| 1572 | 1574 |
| 1573 class Base { | 1575 class Base { |
| 1574 A f; | 1576 A f; |
| 1575 } | 1577 } |
| 1576 | 1578 |
| 1577 class T1 extends Base { | 1579 class T1 extends Base { |
| 1578 /*severe:InvalidFieldOverride,severe:InvalidMethodOverride*/B get
f => null; | 1580 /*severe:INVALID_FIELD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE*/B
get f => null; |
| 1579 } | 1581 } |
| 1580 | 1582 |
| 1581 class T2 extends Base { | 1583 class T2 extends Base { |
| 1582 /*severe:InvalidFieldOverride,severe:InvalidMethodOverride*/set f(
B b) => null; | 1584 /*severe:INVALID_FIELD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE*/se
t f(B b) => null; |
| 1583 } | 1585 } |
| 1584 | 1586 |
| 1585 class T3 extends Base { | 1587 class T3 extends Base { |
| 1586 /*severe:InvalidFieldOverride,severe:InvalidMethodOverride*/final
B f; | 1588 /*severe:INVALID_FIELD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE*/fi
nal B f; |
| 1587 } | 1589 } |
| 1588 class T4 extends Base { | 1590 class T4 extends Base { |
| 1589 // two: one for the getter one for the setter. | 1591 // two: one for the getter one for the setter. |
| 1590 /*severe:InvalidFieldOverride,severe:InvalidMethodOverride,severe:
InvalidMethodOverride*/B f; | 1592 /*severe:INVALID_FIELD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE,sev
ere:INVALID_METHOD_OVERRIDE*/B f; |
| 1591 } | 1593 } |
| 1592 | 1594 |
| 1593 class T5 implements Base { | 1595 class T5 implements Base { |
| 1594 /*severe:InvalidMethodOverride*/B get f => null; | 1596 /*severe:INVALID_METHOD_OVERRIDE*/B get f => null; |
| 1595 } | 1597 } |
| 1596 | 1598 |
| 1597 class T6 implements Base { | 1599 class T6 implements Base { |
| 1598 /*severe:InvalidMethodOverride*/set f(B b) => null; | 1600 /*severe:INVALID_METHOD_OVERRIDE*/set f(B b) => null; |
| 1599 } | 1601 } |
| 1600 | 1602 |
| 1601 class T7 implements Base { | 1603 class T7 implements Base { |
| 1602 /*severe:InvalidMethodOverride*/final B f; | 1604 /*severe:INVALID_METHOD_OVERRIDE*/final B f; |
| 1603 } | 1605 } |
| 1604 class T8 implements Base { | 1606 class T8 implements Base { |
| 1605 // two: one for the getter one for the setter. | 1607 // two: one for the getter one for the setter. |
| 1606 /*severe:InvalidMethodOverride,severe:InvalidMethodOverride*/B f; | 1608 /*severe:INVALID_METHOD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE*/B
f; |
| 1607 } | 1609 } |
| 1608 ''' | 1610 ''' |
| 1609 }); | 1611 }); |
| 1610 | 1612 |
| 1611 testChecker('child override 2', { | 1613 testChecker('child override 2', { |
| 1612 '/main.dart': ''' | 1614 '/main.dart': ''' |
| 1613 class A {} | 1615 class A {} |
| 1614 class B {} | 1616 class B {} |
| 1615 | 1617 |
| 1616 class Base { | 1618 class Base { |
| 1617 m(A a) {} | 1619 m(A a) {} |
| 1618 } | 1620 } |
| 1619 | 1621 |
| 1620 class Test extends Base { | 1622 class Test extends Base { |
| 1621 /*severe:InvalidMethodOverride*/m(B a) {} | 1623 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {} |
| 1622 } | 1624 } |
| 1623 ''' | 1625 ''' |
| 1624 }); | 1626 }); |
| 1625 testChecker('grandchild override', { | 1627 testChecker('grandchild override', { |
| 1626 '/main.dart': ''' | 1628 '/main.dart': ''' |
| 1627 class A {} | 1629 class A {} |
| 1628 class B {} | 1630 class B {} |
| 1629 | 1631 |
| 1630 class Grandparent { | 1632 class Grandparent { |
| 1631 m(A a) {} | 1633 m(A a) {} |
| 1632 int x; | 1634 int x; |
| 1633 } | 1635 } |
| 1634 class Parent extends Grandparent { | 1636 class Parent extends Grandparent { |
| 1635 } | 1637 } |
| 1636 | 1638 |
| 1637 class Test extends Parent { | 1639 class Test extends Parent { |
| 1638 /*severe:InvalidMethodOverride*/m(B a) {} | 1640 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {} |
| 1639 /*severe:InvalidFieldOverride*/int x; | 1641 /*severe:INVALID_FIELD_OVERRIDE*/int x; |
| 1640 } | 1642 } |
| 1641 ''' | 1643 ''' |
| 1642 }); | 1644 }); |
| 1643 | 1645 |
| 1644 testChecker('double override', { | 1646 testChecker('double override', { |
| 1645 '/main.dart': ''' | 1647 '/main.dart': ''' |
| 1646 class A {} | 1648 class A {} |
| 1647 class B {} | 1649 class B {} |
| 1648 | 1650 |
| 1649 class Grandparent { | 1651 class Grandparent { |
| 1650 m(A a) {} | 1652 m(A a) {} |
| 1651 } | 1653 } |
| 1652 class Parent extends Grandparent { | 1654 class Parent extends Grandparent { |
| 1653 m(A a) {} | 1655 m(A a) {} |
| 1654 } | 1656 } |
| 1655 | 1657 |
| 1656 class Test extends Parent { | 1658 class Test extends Parent { |
| 1657 // Reported only once | 1659 // Reported only once |
| 1658 /*severe:InvalidMethodOverride*/m(B a) {} | 1660 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {} |
| 1659 } | 1661 } |
| 1660 ''' | 1662 ''' |
| 1661 }); | 1663 }); |
| 1662 | 1664 |
| 1663 testChecker('double override 2', { | 1665 testChecker('double override 2', { |
| 1664 '/main.dart': ''' | 1666 '/main.dart': ''' |
| 1665 class A {} | 1667 class A {} |
| 1666 class B {} | 1668 class B {} |
| 1667 | 1669 |
| 1668 class Grandparent { | 1670 class Grandparent { |
| 1669 m(A a) {} | 1671 m(A a) {} |
| 1670 } | 1672 } |
| 1671 class Parent extends Grandparent { | 1673 class Parent extends Grandparent { |
| 1672 /*severe:InvalidMethodOverride*/m(B a) {} | 1674 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {} |
| 1673 } | 1675 } |
| 1674 | 1676 |
| 1675 class Test extends Parent { | 1677 class Test extends Parent { |
| 1676 m(B a) {} | 1678 m(B a) {} |
| 1677 } | 1679 } |
| 1678 ''' | 1680 ''' |
| 1679 }); | 1681 }); |
| 1680 | 1682 |
| 1681 testChecker('mixin override to base', { | 1683 testChecker('mixin override to base', { |
| 1682 '/main.dart': ''' | 1684 '/main.dart': ''' |
| 1683 class A {} | 1685 class A {} |
| 1684 class B {} | 1686 class B {} |
| 1685 | 1687 |
| 1686 class Base { | 1688 class Base { |
| 1687 m(A a) {} | 1689 m(A a) {} |
| 1688 int x; | 1690 int x; |
| 1689 } | 1691 } |
| 1690 | 1692 |
| 1691 class M1 { | 1693 class M1 { |
| 1692 m(B a) {} | 1694 m(B a) {} |
| 1693 } | 1695 } |
| 1694 | 1696 |
| 1695 class M2 { | 1697 class M2 { |
| 1696 int x; | 1698 int x; |
| 1697 } | 1699 } |
| 1698 | 1700 |
| 1699 class T1 extends Base with /*severe:InvalidMethodOverride*/M1 {} | 1701 class T1 extends Base with /*severe:INVALID_METHOD_OVERRIDE*/M1 {} |
| 1700 class T2 extends Base with /*severe:InvalidMethodOverride*/M1, /*sev
ere:InvalidFieldOverride*/M2 {} | 1702 class T2 extends Base with /*severe:INVALID_METHOD_OVERRIDE*/M1, /*s
evere:INVALID_FIELD_OVERRIDE*/M2 {} |
| 1701 class T3 extends Base with /*severe:InvalidFieldOverride*/M2, /*seve
re:InvalidMethodOverride*/M1 {} | 1703 class T3 extends Base with /*severe:INVALID_FIELD_OVERRIDE*/M2, /*se
vere:INVALID_METHOD_OVERRIDE*/M1 {} |
| 1702 ''' | 1704 ''' |
| 1703 }); | 1705 }); |
| 1704 | 1706 |
| 1705 testChecker('mixin override to mixin', { | 1707 testChecker('mixin override to mixin', { |
| 1706 '/main.dart': ''' | 1708 '/main.dart': ''' |
| 1707 class A {} | 1709 class A {} |
| 1708 class B {} | 1710 class B {} |
| 1709 | 1711 |
| 1710 class Base { | 1712 class Base { |
| 1711 } | 1713 } |
| 1712 | 1714 |
| 1713 class M1 { | 1715 class M1 { |
| 1714 m(B a) {} | 1716 m(B a) {} |
| 1715 int x; | 1717 int x; |
| 1716 } | 1718 } |
| 1717 | 1719 |
| 1718 class M2 { | 1720 class M2 { |
| 1719 m(A a) {} | 1721 m(A a) {} |
| 1720 int x; | 1722 int x; |
| 1721 } | 1723 } |
| 1722 | 1724 |
| 1723 class T1 extends Base with M1, /*severe:InvalidMethodOverride,severe
:InvalidFieldOverride*/M2 {} | 1725 class T1 extends Base with M1, /*severe:INVALID_METHOD_OVERRIDE,seve
re:INVALID_FIELD_OVERRIDE*/M2 {} |
| 1724 ''' | 1726 ''' |
| 1725 }); | 1727 }); |
| 1726 | 1728 |
| 1727 // This is a regression test for a bug in an earlier implementation were | 1729 // This is a regression test for a bug in an earlier implementation were |
| 1728 // names were hiding errors if the first mixin override looked correct, | 1730 // names were hiding errors if the first mixin override looked correct, |
| 1729 // but subsequent ones did not. | 1731 // but subsequent ones did not. |
| 1730 testChecker('no duplicate mixin override', { | 1732 testChecker('no duplicate mixin override', { |
| 1731 '/main.dart': ''' | 1733 '/main.dart': ''' |
| 1732 class A {} | 1734 class A {} |
| 1733 class B {} | 1735 class B {} |
| 1734 | 1736 |
| 1735 class Base { | 1737 class Base { |
| 1736 m(A a) {} | 1738 m(A a) {} |
| 1737 } | 1739 } |
| 1738 | 1740 |
| 1739 class M1 { | 1741 class M1 { |
| 1740 m(A a) {} | 1742 m(A a) {} |
| 1741 } | 1743 } |
| 1742 | 1744 |
| 1743 class M2 { | 1745 class M2 { |
| 1744 m(B a) {} | 1746 m(B a) {} |
| 1745 } | 1747 } |
| 1746 | 1748 |
| 1747 class M3 { | 1749 class M3 { |
| 1748 m(B a) {} | 1750 m(B a) {} |
| 1749 } | 1751 } |
| 1750 | 1752 |
| 1751 class T1 extends Base | 1753 class T1 extends Base |
| 1752 with M1, /*severe:InvalidMethodOverride*/M2, M3 {} | 1754 with M1, /*severe:INVALID_METHOD_OVERRIDE*/M2, M3 {} |
| 1753 ''' | 1755 ''' |
| 1754 }); | 1756 }); |
| 1755 | 1757 |
| 1756 testChecker('class override of interface', { | 1758 testChecker('class override of interface', { |
| 1757 '/main.dart': ''' | 1759 '/main.dart': ''' |
| 1758 class A {} | 1760 class A {} |
| 1759 class B {} | 1761 class B {} |
| 1760 | 1762 |
| 1761 abstract class I { | 1763 abstract class I { |
| 1762 m(A a); | 1764 m(A a); |
| 1763 } | 1765 } |
| 1764 | 1766 |
| 1765 class T1 implements I { | 1767 class T1 implements I { |
| 1766 /*severe:InvalidMethodOverride*/m(B a) {} | 1768 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {} |
| 1767 } | 1769 } |
| 1768 ''' | 1770 ''' |
| 1769 }); | 1771 }); |
| 1770 | 1772 |
| 1771 testChecker('base class override to child interface', { | 1773 testChecker('base class override to child interface', { |
| 1772 '/main.dart': ''' | 1774 '/main.dart': ''' |
| 1773 class A {} | 1775 class A {} |
| 1774 class B {} | 1776 class B {} |
| 1775 | 1777 |
| 1776 abstract class I { | 1778 abstract class I { |
| 1777 m(A a); | 1779 m(A a); |
| 1778 } | 1780 } |
| 1779 | 1781 |
| 1780 class Base { | 1782 class Base { |
| 1781 m(B a) {} | 1783 m(B a) {} |
| 1782 } | 1784 } |
| 1783 | 1785 |
| 1784 | 1786 |
| 1785 class T1 /*severe:InvalidMethodOverride*/extends Base implements I { | 1787 class T1 /*severe:INVALID_METHOD_OVERRIDE*/extends Base implements I
{ |
| 1786 } | 1788 } |
| 1787 ''' | 1789 ''' |
| 1788 }); | 1790 }); |
| 1789 | 1791 |
| 1790 testChecker('mixin override of interface', { | 1792 testChecker('mixin override of interface', { |
| 1791 '/main.dart': ''' | 1793 '/main.dart': ''' |
| 1792 class A {} | 1794 class A {} |
| 1793 class B {} | 1795 class B {} |
| 1794 | 1796 |
| 1795 abstract class I { | 1797 abstract class I { |
| 1796 m(A a); | 1798 m(A a); |
| 1797 } | 1799 } |
| 1798 | 1800 |
| 1799 class M { | 1801 class M { |
| 1800 m(B a) {} | 1802 m(B a) {} |
| 1801 } | 1803 } |
| 1802 | 1804 |
| 1803 class T1 extends Object with /*severe:InvalidMethodOverride*/M | 1805 class T1 extends Object with /*severe:INVALID_METHOD_OVERRIDE*/M |
| 1804 implements I {} | 1806 implements I {} |
| 1805 ''' | 1807 ''' |
| 1806 }); | 1808 }); |
| 1807 | 1809 |
| 1808 // This is a case were it is incorrect to say that the base class | 1810 // This is a case were it is incorrect to say that the base class |
| 1809 // incorrectly overrides the interface. | 1811 // incorrectly overrides the interface. |
| 1810 testChecker( | 1812 testChecker( |
| 1811 'no errors if subclass correctly overrides base and interface', { | 1813 'no errors if subclass correctly overrides base and interface', { |
| 1812 '/main.dart': ''' | 1814 '/main.dart': ''' |
| 1813 class A {} | 1815 class A {} |
| 1814 class B {} | 1816 class B {} |
| 1815 | 1817 |
| 1816 class Base { | 1818 class Base { |
| 1817 m(A a) {} | 1819 m(A a) {} |
| 1818 } | 1820 } |
| 1819 | 1821 |
| 1820 class I1 { | 1822 class I1 { |
| 1821 m(B a) {} | 1823 m(B a) {} |
| 1822 } | 1824 } |
| 1823 | 1825 |
| 1824 class T1 /*severe:InvalidMethodOverride*/extends Base | 1826 class T1 /*severe:INVALID_METHOD_OVERRIDE*/extends Base |
| 1825 implements I1 {} | 1827 implements I1 {} |
| 1826 | 1828 |
| 1827 class T2 extends Base implements I1 { | 1829 class T2 extends Base implements I1 { |
| 1828 /*severe:InvalidMethodOverride,severe:InvalidMethodOverride*/m(a
) {} | 1830 /*severe:INVALID_METHOD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE*
/m(a) {} |
| 1829 } | 1831 } |
| 1830 | 1832 |
| 1831 class T3 extends Object with /*severe:InvalidMethodOverride*/Base | 1833 class T3 extends Object with /*severe:INVALID_METHOD_OVERRIDE*/Base |
| 1832 implements I1 {} | 1834 implements I1 {} |
| 1833 | 1835 |
| 1834 class T4 extends Object with Base implements I1 { | 1836 class T4 extends Object with Base implements I1 { |
| 1835 /*severe:InvalidMethodOverride,severe:InvalidMethodOverride*/m(a
) {} | 1837 /*severe:INVALID_METHOD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE*
/m(a) {} |
| 1836 } | 1838 } |
| 1837 ''' | 1839 ''' |
| 1838 }); | 1840 }); |
| 1839 }); | 1841 }); |
| 1840 | 1842 |
| 1841 group('class override of grand interface', () { | 1843 group('class override of grand interface', () { |
| 1842 testChecker('interface of interface of child', { | 1844 testChecker('interface of interface of child', { |
| 1843 '/main.dart': ''' | 1845 '/main.dart': ''' |
| 1844 class A {} | 1846 class A {} |
| 1845 class B {} | 1847 class B {} |
| 1846 | 1848 |
| 1847 abstract class I1 { | 1849 abstract class I1 { |
| 1848 m(A a); | 1850 m(A a); |
| 1849 } | 1851 } |
| 1850 abstract class I2 implements I1 {} | 1852 abstract class I2 implements I1 {} |
| 1851 | 1853 |
| 1852 class T1 implements I2 { | 1854 class T1 implements I2 { |
| 1853 /*severe:InvalidMethodOverride*/m(B a) {} | 1855 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {} |
| 1854 } | 1856 } |
| 1855 ''' | 1857 ''' |
| 1856 }); | 1858 }); |
| 1857 testChecker('superclass of interface of child', { | 1859 testChecker('superclass of interface of child', { |
| 1858 '/main.dart': ''' | 1860 '/main.dart': ''' |
| 1859 class A {} | 1861 class A {} |
| 1860 class B {} | 1862 class B {} |
| 1861 | 1863 |
| 1862 abstract class I1 { | 1864 abstract class I1 { |
| 1863 m(A a); | 1865 m(A a); |
| 1864 } | 1866 } |
| 1865 abstract class I2 extends I1 {} | 1867 abstract class I2 extends I1 {} |
| 1866 | 1868 |
| 1867 class T1 implements I2 { | 1869 class T1 implements I2 { |
| 1868 /*severe:InvalidMethodOverride*/m(B a) {} | 1870 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {} |
| 1869 } | 1871 } |
| 1870 ''' | 1872 ''' |
| 1871 }); | 1873 }); |
| 1872 testChecker('mixin of interface of child', { | 1874 testChecker('mixin of interface of child', { |
| 1873 '/main.dart': ''' | 1875 '/main.dart': ''' |
| 1874 class A {} | 1876 class A {} |
| 1875 class B {} | 1877 class B {} |
| 1876 | 1878 |
| 1877 abstract class M1 { | 1879 abstract class M1 { |
| 1878 m(A a); | 1880 m(A a); |
| 1879 } | 1881 } |
| 1880 abstract class I2 extends Object with M1 {} | 1882 abstract class I2 extends Object with M1 {} |
| 1881 | 1883 |
| 1882 class T1 implements I2 { | 1884 class T1 implements I2 { |
| 1883 /*severe:InvalidMethodOverride*/m(B a) {} | 1885 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {} |
| 1884 } | 1886 } |
| 1885 ''' | 1887 ''' |
| 1886 }); | 1888 }); |
| 1887 testChecker('interface of abstract superclass', { | 1889 testChecker('interface of abstract superclass', { |
| 1888 '/main.dart': ''' | 1890 '/main.dart': ''' |
| 1889 class A {} | 1891 class A {} |
| 1890 class B {} | 1892 class B {} |
| 1891 | 1893 |
| 1892 abstract class I1 { | 1894 abstract class I1 { |
| 1893 m(A a); | 1895 m(A a); |
| 1894 } | 1896 } |
| 1895 abstract class Base implements I1 {} | 1897 abstract class Base implements I1 {} |
| 1896 | 1898 |
| 1897 class T1 extends Base { | 1899 class T1 extends Base { |
| 1898 /*severe:InvalidMethodOverride*/m(B a) {} | 1900 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {} |
| 1899 } | 1901 } |
| 1900 ''' | 1902 ''' |
| 1901 }); | 1903 }); |
| 1902 testChecker('interface of concrete superclass', { | 1904 testChecker('interface of concrete superclass', { |
| 1903 '/main.dart': ''' | 1905 '/main.dart': ''' |
| 1904 class A {} | 1906 class A {} |
| 1905 class B {} | 1907 class B {} |
| 1906 | 1908 |
| 1907 abstract class I1 { | 1909 abstract class I1 { |
| 1908 m(A a); | 1910 m(A a); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1930 | 1932 |
| 1931 abstract class I1 { | 1933 abstract class I1 { |
| 1932 m(A a); | 1934 m(A a); |
| 1933 } | 1935 } |
| 1934 abstract class I2 implements I1 {} | 1936 abstract class I2 implements I1 {} |
| 1935 | 1937 |
| 1936 class M { | 1938 class M { |
| 1937 m(B a) {} | 1939 m(B a) {} |
| 1938 } | 1940 } |
| 1939 | 1941 |
| 1940 class T1 extends Object with /*severe:InvalidMethodOverride*/M | 1942 class T1 extends Object with /*severe:INVALID_METHOD_OVERRIDE*/M |
| 1941 implements I2 { | 1943 implements I2 { |
| 1942 } | 1944 } |
| 1943 ''' | 1945 ''' |
| 1944 }); | 1946 }); |
| 1945 testChecker('superclass of interface of child', { | 1947 testChecker('superclass of interface of child', { |
| 1946 '/main.dart': ''' | 1948 '/main.dart': ''' |
| 1947 class A {} | 1949 class A {} |
| 1948 class B {} | 1950 class B {} |
| 1949 | 1951 |
| 1950 abstract class I1 { | 1952 abstract class I1 { |
| 1951 m(A a); | 1953 m(A a); |
| 1952 } | 1954 } |
| 1953 abstract class I2 extends I1 {} | 1955 abstract class I2 extends I1 {} |
| 1954 | 1956 |
| 1955 class M { | 1957 class M { |
| 1956 m(B a) {} | 1958 m(B a) {} |
| 1957 } | 1959 } |
| 1958 | 1960 |
| 1959 class T1 extends Object with /*severe:InvalidMethodOverride*/M | 1961 class T1 extends Object with /*severe:INVALID_METHOD_OVERRIDE*/M |
| 1960 implements I2 { | 1962 implements I2 { |
| 1961 } | 1963 } |
| 1962 ''' | 1964 ''' |
| 1963 }); | 1965 }); |
| 1964 testChecker('mixin of interface of child', { | 1966 testChecker('mixin of interface of child', { |
| 1965 '/main.dart': ''' | 1967 '/main.dart': ''' |
| 1966 class A {} | 1968 class A {} |
| 1967 class B {} | 1969 class B {} |
| 1968 | 1970 |
| 1969 abstract class M1 { | 1971 abstract class M1 { |
| 1970 m(A a); | 1972 m(A a); |
| 1971 } | 1973 } |
| 1972 abstract class I2 extends Object with M1 {} | 1974 abstract class I2 extends Object with M1 {} |
| 1973 | 1975 |
| 1974 class M { | 1976 class M { |
| 1975 m(B a) {} | 1977 m(B a) {} |
| 1976 } | 1978 } |
| 1977 | 1979 |
| 1978 class T1 extends Object with /*severe:InvalidMethodOverride*/M | 1980 class T1 extends Object with /*severe:INVALID_METHOD_OVERRIDE*/M |
| 1979 implements I2 { | 1981 implements I2 { |
| 1980 } | 1982 } |
| 1981 ''' | 1983 ''' |
| 1982 }); | 1984 }); |
| 1983 testChecker('interface of abstract superclass', { | 1985 testChecker('interface of abstract superclass', { |
| 1984 '/main.dart': ''' | 1986 '/main.dart': ''' |
| 1985 class A {} | 1987 class A {} |
| 1986 class B {} | 1988 class B {} |
| 1987 | 1989 |
| 1988 abstract class I1 { | 1990 abstract class I1 { |
| 1989 m(A a); | 1991 m(A a); |
| 1990 } | 1992 } |
| 1991 abstract class Base implements I1 {} | 1993 abstract class Base implements I1 {} |
| 1992 | 1994 |
| 1993 class M { | 1995 class M { |
| 1994 m(B a) {} | 1996 m(B a) {} |
| 1995 } | 1997 } |
| 1996 | 1998 |
| 1997 class T1 extends Base with /*severe:InvalidMethodOverride*/M { | 1999 class T1 extends Base with /*severe:INVALID_METHOD_OVERRIDE*/M { |
| 1998 } | 2000 } |
| 1999 ''' | 2001 ''' |
| 2000 }); | 2002 }); |
| 2001 testChecker('interface of concrete superclass', { | 2003 testChecker('interface of concrete superclass', { |
| 2002 '/main.dart': ''' | 2004 '/main.dart': ''' |
| 2003 class A {} | 2005 class A {} |
| 2004 class B {} | 2006 class B {} |
| 2005 | 2007 |
| 2006 abstract class I1 { | 2008 abstract class I1 { |
| 2007 m(A a); | 2009 m(A a); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 2029 | 2031 |
| 2030 abstract class I1 { | 2032 abstract class I1 { |
| 2031 m(A a); | 2033 m(A a); |
| 2032 } | 2034 } |
| 2033 abstract class I2 implements I1 {} | 2035 abstract class I2 implements I1 {} |
| 2034 | 2036 |
| 2035 class Base { | 2037 class Base { |
| 2036 m(B a) {} | 2038 m(B a) {} |
| 2037 } | 2039 } |
| 2038 | 2040 |
| 2039 class T1 /*severe:InvalidMethodOverride*/extends Base | 2041 class T1 /*severe:INVALID_METHOD_OVERRIDE*/extends Base |
| 2040 implements I2 { | 2042 implements I2 { |
| 2041 } | 2043 } |
| 2042 ''' | 2044 ''' |
| 2043 }); | 2045 }); |
| 2044 testChecker('superclass of interface of child', { | 2046 testChecker('superclass of interface of child', { |
| 2045 '/main.dart': ''' | 2047 '/main.dart': ''' |
| 2046 class A {} | 2048 class A {} |
| 2047 class B {} | 2049 class B {} |
| 2048 | 2050 |
| 2049 abstract class I1 { | 2051 abstract class I1 { |
| 2050 m(A a); | 2052 m(A a); |
| 2051 } | 2053 } |
| 2052 abstract class I2 extends I1 {} | 2054 abstract class I2 extends I1 {} |
| 2053 | 2055 |
| 2054 class Base { | 2056 class Base { |
| 2055 m(B a) {} | 2057 m(B a) {} |
| 2056 } | 2058 } |
| 2057 | 2059 |
| 2058 class T1 /*severe:InvalidMethodOverride*/extends Base | 2060 class T1 /*severe:INVALID_METHOD_OVERRIDE*/extends Base |
| 2059 implements I2 { | 2061 implements I2 { |
| 2060 } | 2062 } |
| 2061 ''' | 2063 ''' |
| 2062 }); | 2064 }); |
| 2063 testChecker('mixin of interface of child', { | 2065 testChecker('mixin of interface of child', { |
| 2064 '/main.dart': ''' | 2066 '/main.dart': ''' |
| 2065 class A {} | 2067 class A {} |
| 2066 class B {} | 2068 class B {} |
| 2067 | 2069 |
| 2068 abstract class M1 { | 2070 abstract class M1 { |
| 2069 m(A a); | 2071 m(A a); |
| 2070 } | 2072 } |
| 2071 abstract class I2 extends Object with M1 {} | 2073 abstract class I2 extends Object with M1 {} |
| 2072 | 2074 |
| 2073 class Base { | 2075 class Base { |
| 2074 m(B a) {} | 2076 m(B a) {} |
| 2075 } | 2077 } |
| 2076 | 2078 |
| 2077 class T1 /*severe:InvalidMethodOverride*/extends Base | 2079 class T1 /*severe:INVALID_METHOD_OVERRIDE*/extends Base |
| 2078 implements I2 { | 2080 implements I2 { |
| 2079 } | 2081 } |
| 2080 ''' | 2082 ''' |
| 2081 }); | 2083 }); |
| 2082 testChecker('interface of abstract superclass', { | 2084 testChecker('interface of abstract superclass', { |
| 2083 '/main.dart': ''' | 2085 '/main.dart': ''' |
| 2084 class A {} | 2086 class A {} |
| 2085 class B {} | 2087 class B {} |
| 2086 | 2088 |
| 2087 abstract class I1 { | 2089 abstract class I1 { |
| 2088 m(A a); | 2090 m(A a); |
| 2089 } | 2091 } |
| 2090 | 2092 |
| 2091 abstract class Base implements I1 { | 2093 abstract class Base implements I1 { |
| 2092 /*severe:InvalidMethodOverride*/m(B a) {} | 2094 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {} |
| 2093 } | 2095 } |
| 2094 | 2096 |
| 2095 class T1 extends Base { | 2097 class T1 extends Base { |
| 2096 // we consider the base class incomplete because it is | 2098 // we consider the base class incomplete because it is |
| 2097 // abstract, so we report the error here too. | 2099 // abstract, so we report the error here too. |
| 2098 // TODO(sigmund): consider tracking overrides in a fine-grain | 2100 // TODO(sigmund): consider tracking overrides in a fine-grain |
| 2099 // manner, then this and the double-overrides would not be | 2101 // manner, then this and the double-overrides would not be |
| 2100 // reported. | 2102 // reported. |
| 2101 /*severe:InvalidMethodOverride*/m(B a) {} | 2103 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {} |
| 2102 } | 2104 } |
| 2103 ''' | 2105 ''' |
| 2104 }); | 2106 }); |
| 2105 testChecker('interface of concrete superclass', { | 2107 testChecker('interface of concrete superclass', { |
| 2106 '/main.dart': ''' | 2108 '/main.dart': ''' |
| 2107 class A {} | 2109 class A {} |
| 2108 class B {} | 2110 class B {} |
| 2109 | 2111 |
| 2110 abstract class I1 { | 2112 abstract class I1 { |
| 2111 m(A a); | 2113 m(A a); |
| 2112 } | 2114 } |
| 2113 | 2115 |
| 2114 class Base implements I1 { | 2116 class Base implements I1 { |
| 2115 /*severe:InvalidMethodOverride*/m(B a) {} | 2117 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {} |
| 2116 } | 2118 } |
| 2117 | 2119 |
| 2118 class T1 extends Base { | 2120 class T1 extends Base { |
| 2119 m(B a) {} | 2121 m(B a) {} |
| 2120 } | 2122 } |
| 2121 ''' | 2123 ''' |
| 2122 }); | 2124 }); |
| 2123 }); | 2125 }); |
| 2124 | 2126 |
| 2125 group('no duplicate reports from overriding interfaces', () { | 2127 group('no duplicate reports from overriding interfaces', () { |
| 2126 testChecker('type overrides same method in multiple interfaces', { | 2128 testChecker('type overrides same method in multiple interfaces', { |
| 2127 '/main.dart': ''' | 2129 '/main.dart': ''' |
| 2128 class A {} | 2130 class A {} |
| 2129 class B {} | 2131 class B {} |
| 2130 | 2132 |
| 2131 abstract class I1 { | 2133 abstract class I1 { |
| 2132 m(A a); | 2134 m(A a); |
| 2133 } | 2135 } |
| 2134 abstract class I2 implements I1 { | 2136 abstract class I2 implements I1 { |
| 2135 m(A a); | 2137 m(A a); |
| 2136 } | 2138 } |
| 2137 | 2139 |
| 2138 class Base { | 2140 class Base { |
| 2139 } | 2141 } |
| 2140 | 2142 |
| 2141 class T1 implements I2 { | 2143 class T1 implements I2 { |
| 2142 /*severe:InvalidMethodOverride*/m(B a) {} | 2144 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {} |
| 2143 } | 2145 } |
| 2144 ''' | 2146 ''' |
| 2145 }); | 2147 }); |
| 2146 | 2148 |
| 2147 testChecker('type and base type override same method in interface', { | 2149 testChecker('type and base type override same method in interface', { |
| 2148 '/main.dart': ''' | 2150 '/main.dart': ''' |
| 2149 class A {} | 2151 class A {} |
| 2150 class B {} | 2152 class B {} |
| 2151 | 2153 |
| 2152 abstract class I1 { | 2154 abstract class I1 { |
| 2153 m(A a); | 2155 m(A a); |
| 2154 } | 2156 } |
| 2155 | 2157 |
| 2156 class Base { | 2158 class Base { |
| 2157 m(B a); | 2159 m(B a); |
| 2158 } | 2160 } |
| 2159 | 2161 |
| 2160 // Note: no error reported in `extends Base` to avoid duplicating | 2162 // Note: no error reported in `extends Base` to avoid duplicating |
| 2161 // the error in T1. | 2163 // the error in T1. |
| 2162 class T1 extends Base implements I1 { | 2164 class T1 extends Base implements I1 { |
| 2163 /*severe:InvalidMethodOverride*/m(B a) {} | 2165 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {} |
| 2164 } | 2166 } |
| 2165 | 2167 |
| 2166 // If there is no error in the class, we do report the error at | 2168 // If there is no error in the class, we do report the error at |
| 2167 // the base class: | 2169 // the base class: |
| 2168 class T2 /*severe:InvalidMethodOverride*/extends Base | 2170 class T2 /*severe:INVALID_METHOD_OVERRIDE*/extends Base |
| 2169 implements I1 { | 2171 implements I1 { |
| 2170 } | 2172 } |
| 2171 ''' | 2173 ''' |
| 2172 }); | 2174 }); |
| 2173 | 2175 |
| 2174 testChecker('type and mixin override same method in interface', { | 2176 testChecker('type and mixin override same method in interface', { |
| 2175 '/main.dart': ''' | 2177 '/main.dart': ''' |
| 2176 class A {} | 2178 class A {} |
| 2177 class B {} | 2179 class B {} |
| 2178 | 2180 |
| 2179 abstract class I1 { | 2181 abstract class I1 { |
| 2180 m(A a); | 2182 m(A a); |
| 2181 } | 2183 } |
| 2182 | 2184 |
| 2183 class M { | 2185 class M { |
| 2184 m(B a); | 2186 m(B a); |
| 2185 } | 2187 } |
| 2186 | 2188 |
| 2187 class T1 extends Object with M implements I1 { | 2189 class T1 extends Object with M implements I1 { |
| 2188 /*severe:InvalidMethodOverride*/m(B a) {} | 2190 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {} |
| 2189 } | 2191 } |
| 2190 | 2192 |
| 2191 class T2 extends Object with /*severe:InvalidMethodOverride*/M | 2193 class T2 extends Object with /*severe:INVALID_METHOD_OVERRIDE*/M |
| 2192 implements I1 { | 2194 implements I1 { |
| 2193 } | 2195 } |
| 2194 ''' | 2196 ''' |
| 2195 }); | 2197 }); |
| 2196 | 2198 |
| 2197 testChecker('two grand types override same method in interface', { | 2199 testChecker('two grand types override same method in interface', { |
| 2198 '/main.dart': ''' | 2200 '/main.dart': ''' |
| 2199 class A {} | 2201 class A {} |
| 2200 class B {} | 2202 class B {} |
| 2201 | 2203 |
| 2202 abstract class I1 { | 2204 abstract class I1 { |
| 2203 m(A a); | 2205 m(A a); |
| 2204 } | 2206 } |
| 2205 | 2207 |
| 2206 class Grandparent { | 2208 class Grandparent { |
| 2207 m(B a) {} | 2209 m(B a) {} |
| 2208 } | 2210 } |
| 2209 | 2211 |
| 2210 class Parent1 extends Grandparent { | 2212 class Parent1 extends Grandparent { |
| 2211 m(B a) {} | 2213 m(B a) {} |
| 2212 } | 2214 } |
| 2213 class Parent2 extends Grandparent { | 2215 class Parent2 extends Grandparent { |
| 2214 } | 2216 } |
| 2215 | 2217 |
| 2216 // Note: otherwise both errors would be reported on this line | 2218 // Note: otherwise both errors would be reported on this line |
| 2217 class T1 /*severe:InvalidMethodOverride*/extends Parent1 | 2219 class T1 /*severe:INVALID_METHOD_OVERRIDE*/extends Parent1 |
| 2218 implements I1 { | 2220 implements I1 { |
| 2219 } | 2221 } |
| 2220 class T2 /*severe:InvalidMethodOverride*/extends Parent2 | 2222 class T2 /*severe:INVALID_METHOD_OVERRIDE*/extends Parent2 |
| 2221 implements I1 { | 2223 implements I1 { |
| 2222 } | 2224 } |
| 2223 ''' | 2225 ''' |
| 2224 }); | 2226 }); |
| 2225 | 2227 |
| 2226 testChecker('two mixins override same method in interface', { | 2228 testChecker('two mixins override same method in interface', { |
| 2227 '/main.dart': ''' | 2229 '/main.dart': ''' |
| 2228 class A {} | 2230 class A {} |
| 2229 class B {} | 2231 class B {} |
| 2230 | 2232 |
| 2231 abstract class I1 { | 2233 abstract class I1 { |
| 2232 m(A a); | 2234 m(A a); |
| 2233 } | 2235 } |
| 2234 | 2236 |
| 2235 class M1 { | 2237 class M1 { |
| 2236 m(B a) {} | 2238 m(B a) {} |
| 2237 } | 2239 } |
| 2238 | 2240 |
| 2239 class M2 { | 2241 class M2 { |
| 2240 m(B a) {} | 2242 m(B a) {} |
| 2241 } | 2243 } |
| 2242 | 2244 |
| 2243 // Here we want to report both, because the error location is | 2245 // Here we want to report both, because the error location is |
| 2244 // different. | 2246 // different. |
| 2245 // TODO(sigmund): should we merge these as well? | 2247 // TODO(sigmund): should we merge these as well? |
| 2246 class T1 extends Object | 2248 class T1 extends Object |
| 2247 with /*severe:InvalidMethodOverride*/M1 | 2249 with /*severe:INVALID_METHOD_OVERRIDE*/M1 |
| 2248 with /*severe:InvalidMethodOverride*/M2 | 2250 with /*severe:INVALID_METHOD_OVERRIDE*/M2 |
| 2249 implements I1 { | 2251 implements I1 { |
| 2250 } | 2252 } |
| 2251 ''' | 2253 ''' |
| 2252 }); | 2254 }); |
| 2253 | 2255 |
| 2254 testChecker('base type and mixin override same method in interface', { | 2256 testChecker('base type and mixin override same method in interface', { |
| 2255 '/main.dart': ''' | 2257 '/main.dart': ''' |
| 2256 class A {} | 2258 class A {} |
| 2257 class B {} | 2259 class B {} |
| 2258 | 2260 |
| 2259 abstract class I1 { | 2261 abstract class I1 { |
| 2260 m(A a); | 2262 m(A a); |
| 2261 } | 2263 } |
| 2262 | 2264 |
| 2263 class Base { | 2265 class Base { |
| 2264 m(B a) {} | 2266 m(B a) {} |
| 2265 } | 2267 } |
| 2266 | 2268 |
| 2267 class M { | 2269 class M { |
| 2268 m(B a) {} | 2270 m(B a) {} |
| 2269 } | 2271 } |
| 2270 | 2272 |
| 2271 // Here we want to report both, because the error location is | 2273 // Here we want to report both, because the error location is |
| 2272 // different. | 2274 // different. |
| 2273 // TODO(sigmund): should we merge these as well? | 2275 // TODO(sigmund): should we merge these as well? |
| 2274 class T1 /*severe:InvalidMethodOverride*/extends Base | 2276 class T1 /*severe:INVALID_METHOD_OVERRIDE*/extends Base |
| 2275 with /*severe:InvalidMethodOverride*/M | 2277 with /*severe:INVALID_METHOD_OVERRIDE*/M |
| 2276 implements I1 { | 2278 implements I1 { |
| 2277 } | 2279 } |
| 2278 ''' | 2280 ''' |
| 2279 }); | 2281 }); |
| 2280 }); | 2282 }); |
| 2281 | 2283 |
| 2282 testChecker('invalid runtime checks', { | 2284 testChecker('invalid runtime checks', { |
| 2283 '/main.dart': ''' | 2285 '/main.dart': ''' |
| 2284 typedef int I2I(int x); | 2286 typedef int I2I(int x); |
| 2285 typedef int D2I(x); | 2287 typedef int D2I(x); |
| 2286 typedef int II2I(int x, int y); | 2288 typedef int II2I(int x, int y); |
| 2287 typedef int DI2I(x, int y); | 2289 typedef int DI2I(x, int y); |
| 2288 typedef int ID2I(int x, y); | 2290 typedef int ID2I(int x, y); |
| 2289 typedef int DD2I(x, y); | 2291 typedef int DD2I(x, y); |
| 2290 | 2292 |
| 2291 typedef I2D(int x); | 2293 typedef I2D(int x); |
| 2292 typedef D2D(x); | 2294 typedef D2D(x); |
| 2293 typedef II2D(int x, int y); | 2295 typedef II2D(int x, int y); |
| 2294 typedef DI2D(x, int y); | 2296 typedef DI2D(x, int y); |
| 2295 typedef ID2D(int x, y); | 2297 typedef ID2D(int x, y); |
| 2296 typedef DD2D(x, y); | 2298 typedef DD2D(x, y); |
| 2297 | 2299 |
| 2298 int foo(int x) => x; | 2300 int foo(int x) => x; |
| 2299 int bar(int x, int y) => x + y; | 2301 int bar(int x, int y) => x + y; |
| 2300 | 2302 |
| 2301 void main() { | 2303 void main() { |
| 2302 bool b; | 2304 bool b; |
| 2303 b = /*info:NonGroundTypeCheckInfo*/foo is I2I; | 2305 b = /*info:NON_GROUND_TYPE_CHECK_INFO*/foo is I2I; |
| 2304 b = /*info:NonGroundTypeCheckInfo*/foo is D2I; | 2306 b = /*info:NON_GROUND_TYPE_CHECK_INFO*/foo is D2I; |
| 2305 b = /*info:NonGroundTypeCheckInfo*/foo is I2D; | 2307 b = /*info:NON_GROUND_TYPE_CHECK_INFO*/foo is I2D; |
| 2306 b = foo is D2D; | 2308 b = foo is D2D; |
| 2307 | 2309 |
| 2308 b = /*info:NonGroundTypeCheckInfo*/bar is II2I; | 2310 b = /*info:NON_GROUND_TYPE_CHECK_INFO*/bar is II2I; |
| 2309 b = /*info:NonGroundTypeCheckInfo*/bar is DI2I; | 2311 b = /*info:NON_GROUND_TYPE_CHECK_INFO*/bar is DI2I; |
| 2310 b = /*info:NonGroundTypeCheckInfo*/bar is ID2I; | 2312 b = /*info:NON_GROUND_TYPE_CHECK_INFO*/bar is ID2I; |
| 2311 b = /*info:NonGroundTypeCheckInfo*/bar is II2D; | 2313 b = /*info:NON_GROUND_TYPE_CHECK_INFO*/bar is II2D; |
| 2312 b = /*info:NonGroundTypeCheckInfo*/bar is DD2I; | 2314 b = /*info:NON_GROUND_TYPE_CHECK_INFO*/bar is DD2I; |
| 2313 b = /*info:NonGroundTypeCheckInfo*/bar is DI2D; | 2315 b = /*info:NON_GROUND_TYPE_CHECK_INFO*/bar is DI2D; |
| 2314 b = /*info:NonGroundTypeCheckInfo*/bar is ID2D; | 2316 b = /*info:NON_GROUND_TYPE_CHECK_INFO*/bar is ID2D; |
| 2315 b = bar is DD2D; | 2317 b = bar is DD2D; |
| 2316 | 2318 |
| 2317 // For as, the validity of checks is deferred to runtime. | 2319 // For as, the validity of checks is deferred to runtime. |
| 2318 Function f; | 2320 Function f; |
| 2319 f = foo as I2I; | 2321 f = foo as I2I; |
| 2320 f = foo as D2I; | 2322 f = foo as D2I; |
| 2321 f = foo as I2D; | 2323 f = foo as I2D; |
| 2322 f = foo as D2D; | 2324 f = foo as D2D; |
| 2323 | 2325 |
| 2324 f = bar as II2I; | 2326 f = bar as II2I; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 2336 group('function modifiers', () { | 2338 group('function modifiers', () { |
| 2337 testChecker('async', { | 2339 testChecker('async', { |
| 2338 '/main.dart': ''' | 2340 '/main.dart': ''' |
| 2339 import 'dart:async'; | 2341 import 'dart:async'; |
| 2340 import 'dart:math' show Random; | 2342 import 'dart:math' show Random; |
| 2341 | 2343 |
| 2342 dynamic x; | 2344 dynamic x; |
| 2343 | 2345 |
| 2344 foo1() async => x; | 2346 foo1() async => x; |
| 2345 Future foo2() async => x; | 2347 Future foo2() async => x; |
| 2346 Future<int> foo3() async => (/*info:DynamicCast*/x); | 2348 Future<int> foo3() async => (/*info:DYNAMIC_CAST*/x); |
| 2347 Future<int> foo4() async => (/*severe:StaticTypeError*/new Future<int>.v
alue(/*info:DynamicCast*/x)); | 2349 Future<int> foo4() async => (/*severe:STATIC_TYPE_ERROR*/new Future<int>
.value(/*info:DYNAMIC_CAST*/x)); |
| 2348 | 2350 |
| 2349 bar1() async { return x; } | 2351 bar1() async { return x; } |
| 2350 Future bar2() async { return x; } | 2352 Future bar2() async { return x; } |
| 2351 Future<int> bar3() async { return (/*info:DynamicCast*/x); } | 2353 Future<int> bar3() async { return (/*info:DYNAMIC_CAST*/x); } |
| 2352 Future<int> bar4() async { return (/*severe:StaticTypeError*/new Future<
int>.value(/*info:DynamicCast*/x)); } | 2354 Future<int> bar4() async { return (/*severe:STATIC_TYPE_ERROR*/new Futur
e<int>.value(/*info:DYNAMIC_CAST*/x)); } |
| 2353 | 2355 |
| 2354 int y; | 2356 int y; |
| 2355 Future<int> z; | 2357 Future<int> z; |
| 2356 | 2358 |
| 2357 void baz() async { | 2359 void baz() async { |
| 2358 int a = /*info:DynamicCast*/await x; | 2360 int a = /*info:DYNAMIC_CAST*/await x; |
| 2359 int b = await y; | 2361 int b = await y; |
| 2360 int c = await z; | 2362 int c = await z; |
| 2361 String d = /*severe:StaticTypeError*/await z; | 2363 String d = /*severe:STATIC_TYPE_ERROR*/await z; |
| 2362 } | 2364 } |
| 2363 | 2365 |
| 2364 Future<bool> get issue_264 async { | 2366 Future<bool> get issue_264 async { |
| 2365 await 42; | 2367 await 42; |
| 2366 if (new Random().nextBool()) { | 2368 if (new Random().nextBool()) { |
| 2367 return true; | 2369 return true; |
| 2368 } else { | 2370 } else { |
| 2369 return /*severe:StaticTypeError*/new Future<bool>.value(false); | 2371 return /*severe:STATIC_TYPE_ERROR*/new Future<bool>.value(false); |
| 2370 } | 2372 } |
| 2371 } | 2373 } |
| 2372 ''' | 2374 ''' |
| 2373 }); | 2375 }); |
| 2374 | 2376 |
| 2375 testChecker('async*', { | 2377 testChecker('async*', { |
| 2376 '/main.dart': ''' | 2378 '/main.dart': ''' |
| 2377 import 'dart:async'; | 2379 import 'dart:async'; |
| 2378 | 2380 |
| 2379 dynamic x; | 2381 dynamic x; |
| 2380 | 2382 |
| 2381 bar1() async* { yield x; } | 2383 bar1() async* { yield x; } |
| 2382 Stream bar2() async* { yield x; } | 2384 Stream bar2() async* { yield x; } |
| 2383 Stream<int> bar3() async* { yield (/*info:DynamicCast*/x); } | 2385 Stream<int> bar3() async* { yield (/*info:DYNAMIC_CAST*/x); } |
| 2384 Stream<int> bar4() async* { yield (/*severe:StaticTypeError*/new Stream<
int>()); } | 2386 Stream<int> bar4() async* { yield (/*severe:STATIC_TYPE_ERROR*/new Strea
m<int>()); } |
| 2385 | 2387 |
| 2386 baz1() async* { yield* (/*info:DynamicCast*/x); } | 2388 baz1() async* { yield* (/*info:DYNAMIC_CAST*/x); } |
| 2387 Stream baz2() async* { yield* (/*info:DynamicCast*/x); } | 2389 Stream baz2() async* { yield* (/*info:DYNAMIC_CAST*/x); } |
| 2388 Stream<int> baz3() async* { yield* (/*warning:DownCastComposite*/x); } | 2390 Stream<int> baz3() async* { yield* (/*warning:DOWN_CAST_COMPOSITE*/x); } |
| 2389 Stream<int> baz4() async* { yield* new Stream<int>(); } | 2391 Stream<int> baz4() async* { yield* new Stream<int>(); } |
| 2390 Stream<int> baz5() async* { yield* (/*info:InferredTypeAllocation*/new S
tream()); } | 2392 Stream<int> baz5() async* { yield* (/*info:INFERRED_TYPE_ALLOCATION*/new
Stream()); } |
| 2391 ''' | 2393 ''' |
| 2392 }); | 2394 }); |
| 2393 | 2395 |
| 2394 testChecker('sync*', { | 2396 testChecker('sync*', { |
| 2395 '/main.dart': ''' | 2397 '/main.dart': ''' |
| 2396 import 'dart:async'; | 2398 import 'dart:async'; |
| 2397 | 2399 |
| 2398 dynamic x; | 2400 dynamic x; |
| 2399 | 2401 |
| 2400 bar1() sync* { yield x; } | 2402 bar1() sync* { yield x; } |
| 2401 Iterable bar2() sync* { yield x; } | 2403 Iterable bar2() sync* { yield x; } |
| 2402 Iterable<int> bar3() sync* { yield (/*info:DynamicCast*/x); } | 2404 Iterable<int> bar3() sync* { yield (/*info:DYNAMIC_CAST*/x); } |
| 2403 Iterable<int> bar4() sync* { yield (/*severe:StaticTypeError*/new Iterab
le<int>()); } | 2405 Iterable<int> bar4() sync* { yield (/*severe:STATIC_TYPE_ERROR*/new Iter
able<int>()); } |
| 2404 | 2406 |
| 2405 baz1() sync* { yield* (/*info:DynamicCast*/x); } | 2407 baz1() sync* { yield* (/*info:DYNAMIC_CAST*/x); } |
| 2406 Iterable baz2() sync* { yield* (/*info:DynamicCast*/x); } | 2408 Iterable baz2() sync* { yield* (/*info:DYNAMIC_CAST*/x); } |
| 2407 Iterable<int> baz3() sync* { yield* (/*warning:DownCastComposite*/x); } | 2409 Iterable<int> baz3() sync* { yield* (/*warning:DOWN_CAST_COMPOSITE*/x);
} |
| 2408 Iterable<int> baz4() sync* { yield* new Iterable<int>(); } | 2410 Iterable<int> baz4() sync* { yield* new Iterable<int>(); } |
| 2409 Iterable<int> baz5() sync* { yield* (/*info:InferredTypeAllocation*/new
Iterable()); } | 2411 Iterable<int> baz5() sync* { yield* (/*info:INFERRED_TYPE_ALLOCATION*/ne
w Iterable()); } |
| 2410 ''' | 2412 ''' |
| 2411 }); | 2413 }); |
| 2412 }); | 2414 }); |
| 2413 } | 2415 } |
| OLD | NEW |