| 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 analyzer.test.src.task.strong.checker_test; | 8 library analyzer.test.src.task.strong.checker_test; |
| 9 | 9 |
| 10 import 'package:unittest/unittest.dart'; | 10 import 'package:unittest/unittest.dart'; |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 x = f(3); |
| 106 // causes the return type of calls to f to be treated as dynamic. | |
| 107 x = /*info:DYNAMIC_CAST should be pass*/f(3); | |
| 108 x = /*severe:STATIC_TYPE_ERROR*/f.col(3.0); | 106 x = /*severe:STATIC_TYPE_ERROR*/f.col(3.0); |
| 109 y = /*info:DYNAMIC_CAST should be severe:STATIC_TYPE_ERROR*/f(3); | 107 y = /*severe:STATIC_TYPE_ERROR*/f(3); |
| 110 y = f.col(3.0); | 108 y = f.col(3.0); |
| 111 f(/*severe:STATIC_TYPE_ERROR*/3.0); | 109 f(/*severe:STATIC_TYPE_ERROR*/3.0); |
| 112 f.col(/*severe:STATIC_TYPE_ERROR*/3); | 110 f.col(/*severe:STATIC_TYPE_ERROR*/3); |
| 113 } | 111 } |
| 114 { | 112 { |
| 115 Function f = new B(); | 113 Function f = new B(); |
| 116 int x; | 114 int x; |
| 117 double y; | 115 double y; |
| 118 x = /*info:DYNAMIC_CAST, info:DYNAMIC_INVOKE*/f(3); | 116 x = /*info:DYNAMIC_CAST, info:DYNAMIC_INVOKE*/f(3); |
| 119 x = /*info:DYNAMIC_CAST, info:DYNAMIC_INVOKE*/f.col(3.0); | 117 x = /*info:DYNAMIC_CAST, info:DYNAMIC_INVOKE*/f.col(3.0); |
| (...skipping 1267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1387 class DerivedFuture3<T> extends Future<T> { | 1385 class DerivedFuture3<T> extends Future<T> { |
| 1388 /*=S*/ then/*<S>*/(Object onValue(T t)) => null; | 1386 /*=S*/ then/*<S>*/(Object onValue(T t)) => null; |
| 1389 } | 1387 } |
| 1390 | 1388 |
| 1391 class DerivedFuture4<A> extends Future<A> { | 1389 class DerivedFuture4<A> extends Future<A> { |
| 1392 /*=B*/ then/*<B>*/(Object onValue(A a)) => null; | 1390 /*=B*/ then/*<B>*/(Object onValue(A a)) => null; |
| 1393 } | 1391 } |
| 1394 ''' | 1392 ''' |
| 1395 }); | 1393 }); |
| 1396 | 1394 |
| 1395 |
| 1396 testChecker('generic methods on different element kinds', { |
| 1397 '/main.dart': ''' |
| 1398 class C<E> { |
| 1399 /*=T*/ f/*<T>*/(/*=T*/ e) => null; |
| 1400 static /*=T*/ g/*<T>*/(/*=T*/ e) => null; |
| 1401 static final h = g; |
| 1402 } |
| 1403 |
| 1404 /*=T*/ topF/*<T>*/(/*=T*/ e) => null; |
| 1405 |
| 1406 var topG = C.g; |
| 1407 |
| 1408 void test/*<S>*/(/*=T*/ pf/*<T>*/(/*=T*/ e)) { |
| 1409 var c = new C<int>(); |
| 1410 var methodCall = c.f/*<int>*/(3); |
| 1411 var localG = C.g; |
| 1412 int staticFieldCall = C.h/*<int>*/(3); |
| 1413 int topFieldCall = topG/*<int>*/(3); |
| 1414 int localVarCall = localG/*<int>*/(3); |
| 1415 int paramCall = pf/*<int>*/(3); |
| 1416 } |
| 1417 ''' |
| 1418 }); |
| 1419 |
| 1397 testChecker('unary operators', { | 1420 testChecker('unary operators', { |
| 1398 '/main.dart': ''' | 1421 '/main.dart': ''' |
| 1399 class A { | 1422 class A { |
| 1400 A operator ~() {} | 1423 A operator ~() {} |
| 1401 A operator +(int x) {} | 1424 A operator +(int x) {} |
| 1402 A operator -(int x) {} | 1425 A operator -(int x) {} |
| 1403 A operator -() {} | 1426 A operator -() {} |
| 1404 } | 1427 } |
| 1405 | 1428 |
| 1406 foo() => new A(); | 1429 foo() => new A(); |
| (...skipping 1062 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2469 | 2492 |
| 2470 baz1() sync* { yield* (/*info:DYNAMIC_CAST*/x); } | 2493 baz1() sync* { yield* (/*info:DYNAMIC_CAST*/x); } |
| 2471 Iterable baz2() sync* { yield* (/*info:DYNAMIC_CAST*/x); } | 2494 Iterable baz2() sync* { yield* (/*info:DYNAMIC_CAST*/x); } |
| 2472 Iterable<int> baz3() sync* { yield* (/*warning:DOWN_CAST_COMPOSITE*/x);
} | 2495 Iterable<int> baz3() sync* { yield* (/*warning:DOWN_CAST_COMPOSITE*/x);
} |
| 2473 Iterable<int> baz4() sync* { yield* new Iterable<int>(); } | 2496 Iterable<int> baz4() sync* { yield* new Iterable<int>(); } |
| 2474 Iterable<int> baz5() sync* { yield* (/*info:INFERRED_TYPE_ALLOCATION*/ne
w Iterable()); } | 2497 Iterable<int> baz5() sync* { yield* (/*info:INFERRED_TYPE_ALLOCATION*/ne
w Iterable()); } |
| 2475 ''' | 2498 ''' |
| 2476 }); | 2499 }); |
| 2477 }); | 2500 }); |
| 2478 } | 2501 } |
| OLD | NEW |