| 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 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 A.c1(p): this.x = /*info:DOWN_CAST_IMPLICIT*/z, this.y = /*info:DYNAMIC_
CAST*/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:INVALID_PARAMETER_DECLARATION*/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:STATIC_TYPE_ERROR*/"hello"); | 248 B() : super(/*severe:STATIC_TYPE_ERROR*/"hello"); |
| 249 | 249 |
| 250 B.c2(int x, String y) : super.c2(/*severe:STATIC_TYPE_ERROR*/y, | 250 B.c2(int x, String y) : super.c2(/*severe:STATIC_TYPE_ERROR*/y, |
| 251 /*severe:STATIC_TYPE_ERROR*/x); | 251 /*severe:STATIC_TYPE_ERROR*/x); |
| 252 | 252 |
| 253 B.c3(num x, Object y) : super.c3(x, /*info:DOWN_CAST_IMPLICIT*/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:DOWN_CAST_IMPLICIT*/z, /*severe:STATIC_TYPE_ERROR
*/z); | 257 A a = new A.c2(/*info:DOWN_CAST_IMPLICIT*/z, /*severe:STATIC_TYPE_ERROR
*/z); |
| 258 var b = new B.c2(/*severe:STATIC_TYPE_ERROR*/"hello", /*info:DOWN_CAST_
IMPLICIT*/obj); | 258 var b = new B.c2(/*severe:STATIC_TYPE_ERROR*/"hello", /*info:DOWN_CAST_
IMPLICIT*/obj); |
| 259 } | 259 } |
| 260 ''' | 260 ''' |
| (...skipping 1083 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1344 /*severe:INVALID_METHOD_OVERRIDE*/A m1(A value) {} | 1344 /*severe:INVALID_METHOD_OVERRIDE*/A m1(A value) {} |
| 1345 /*severe:INVALID_METHOD_OVERRIDE*/C m2(C value) {} | 1345 /*severe:INVALID_METHOD_OVERRIDE*/C m2(C value) {} |
| 1346 /*severe:INVALID_METHOD_OVERRIDE*/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:INVALID_METHOD_OVERRIDE*/dynamic m6(dynamic value) {} | 1349 /*severe:INVALID_METHOD_OVERRIDE*/dynamic m6(dynamic value) {} |
| 1350 } | 1350 } |
| 1351 ''' | 1351 ''' |
| 1352 }); | 1352 }); |
| 1353 | 1353 |
| 1354 testChecker('generic class method override', { |
| 1355 '/main.dart': ''' |
| 1356 class A {} |
| 1357 class B extends A {} |
| 1358 |
| 1359 class Base<T extends B> { |
| 1360 T foo() => null; |
| 1361 } |
| 1362 |
| 1363 class Derived<S extends A> extends Base<B> { |
| 1364 /*severe:INVALID_METHOD_OVERRIDE*/S foo() => null; |
| 1365 } |
| 1366 |
| 1367 class Derived2<S extends B> extends Base<B> { |
| 1368 S foo() => null; |
| 1369 } |
| 1370 ''' |
| 1371 }); |
| 1372 |
| 1373 testChecker('generic method override', { |
| 1374 '/main.dart': ''' |
| 1375 class Future<T> { |
| 1376 /*=S*/ then/*<S>*/(/*=S*/ onValue(T t)) => null; |
| 1377 } |
| 1378 |
| 1379 // These work because they're exactly equal FunctionTypes |
| 1380 class DerivedFuture<T> extends Future<T> { |
| 1381 /*=S*/ then/*<S>*/(/*=S*/ onValue(T t)) => null; |
| 1382 } |
| 1383 |
| 1384 class DerivedFuture2<A> extends Future<A> { |
| 1385 /*=B*/ then/*<B>*/(/*=B*/ onValue(A a)) => null; |
| 1386 } |
| 1387 |
| 1388 // These don't work but should. |
| 1389 class DerivedFuture3<T> extends Future<T> { |
| 1390 /*=/*severe:INVALID_METHOD_OVERRIDE should be pass*/S*/ then/*<S>*/(
Object onValue(T t)) => null; |
| 1391 } |
| 1392 |
| 1393 class DerivedFuture4<A> extends Future<A> { |
| 1394 /*=/*severe:INVALID_METHOD_OVERRIDE should be pass*/B*/ then/*<B>*/(
Object onValue(A a)) => null; |
| 1395 } |
| 1396 ''' |
| 1397 }); |
| 1398 |
| 1354 testChecker('unary operators', { | 1399 testChecker('unary operators', { |
| 1355 '/main.dart': ''' | 1400 '/main.dart': ''' |
| 1356 class A { | 1401 class A { |
| 1357 A operator ~() {} | 1402 A operator ~() {} |
| 1358 A operator +(int x) {} | 1403 A operator +(int x) {} |
| 1359 A operator -(int x) {} | 1404 A operator -(int x) {} |
| 1360 A operator -() {} | 1405 A operator -() {} |
| 1361 } | 1406 } |
| 1362 | 1407 |
| 1363 foo() => new A(); | 1408 foo() => new A(); |
| (...skipping 1062 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2426 | 2471 |
| 2427 baz1() sync* { yield* (/*info:DYNAMIC_CAST*/x); } | 2472 baz1() sync* { yield* (/*info:DYNAMIC_CAST*/x); } |
| 2428 Iterable baz2() sync* { yield* (/*info:DYNAMIC_CAST*/x); } | 2473 Iterable baz2() sync* { yield* (/*info:DYNAMIC_CAST*/x); } |
| 2429 Iterable<int> baz3() sync* { yield* (/*warning:DOWN_CAST_COMPOSITE*/x);
} | 2474 Iterable<int> baz3() sync* { yield* (/*warning:DOWN_CAST_COMPOSITE*/x);
} |
| 2430 Iterable<int> baz4() sync* { yield* new Iterable<int>(); } | 2475 Iterable<int> baz4() sync* { yield* new Iterable<int>(); } |
| 2431 Iterable<int> baz5() sync* { yield* (/*info:INFERRED_TYPE_ALLOCATION*/ne
w Iterable()); } | 2476 Iterable<int> baz5() sync* { yield* (/*info:INFERRED_TYPE_ALLOCATION*/ne
w Iterable()); } |
| 2432 ''' | 2477 ''' |
| 2433 }); | 2478 }); |
| 2434 }); | 2479 }); |
| 2435 } | 2480 } |
| OLD | NEW |