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