| 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'; |
| 11 | 11 |
| 12 import 'strong_test_helper.dart'; | 12 import 'strong_test_helper.dart'; |
| 13 | 13 |
| 14 void main() { | 14 void main() { |
| 15 testChecker('ternary operator', { | 15 testChecker('ternary operator', { |
| 16 '/main.dart': ''' | 16 '/main.dart': ''' |
| 17 abstract class Comparable<T> { | 17 abstract class Comparable<T> { |
| 18 int compareTo(T other); | 18 int compareTo(T other); |
| 19 static int compare(Comparable a, Comparable b) => a.compareTo(b); | 19 static int compare(Comparable a, Comparable b) => a.compareTo(b); |
| 20 } | 20 } |
| 21 typedef int Comparator<T>(T a, T b); | 21 typedef int Comparator<T>(T a, T b); |
| 22 | 22 |
| 23 typedef bool _Predicate<T>(T value); | 23 typedef bool _Predicate<T>(T value); |
| 24 | 24 |
| 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 // TODO(rnystrom): Initializing _comparator should have a cast, since |
| 30 // Comparable. | 30 // K may not always be Comparable. It doesn't currently get one |
| 31 // Initializing _validKey shouldn't need a cast. Currently | 31 // because we're using the spec's LUB on function types, which isn't |
| 32 // it requires inference to work because of dartbug.com/23381 | 32 // sound. |
| 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:DOWN_CAST_COMPOSITE*/(compare == null) | 35 : _comparator = (compare == null) ? Comparable.compare : compare, |
| 36 ? Comparable.compare : compare, | 36 _validKey = (isValidKey != null) ? isValidKey : ((v) => true); |
| 37 _validKey = /*warning:DOWN_CAST_COMPOSITE*/(isValidKey != null) | 37 _Predicate<Object> v = /*warning:DOWN_CAST_COMPOSITE*/(isValidKey !
= null) |
| 38 ? isValidKey : ((v) => true); | 38 ? isValidKey : (/*info:INFERRED_TYPE_CLOSURE
*/(_) => true); |
| 39 _Predicate<Object> _v = /*warning:DOWN_CAST_COMPOSITE*/(isValidKey
!= null) | 39 |
| 40 ? isValidKey : (/*info:INFERRED_TYPE_CLOSURE
*/(v) => true); | 40 v = (isValidKey != null) |
| 41 // TODO(leafp): Fix unimplemented LUB in analyzer | 41 ? v : (/*info:INFERRED_TYPE_CLOSURE*/(_) => true); |
| 42 _v = /*warning:DOWN_CAST_COMPOSITE*/(isValidKey != null) | |
| 43 ? _v : (/*info:INFERRED_TYPE_CLOSURE*/(v) => true); | |
| 44 } | 42 } |
| 45 } | 43 } |
| 46 void main() { | 44 void main() { |
| 47 Object obj = 42; | 45 Object obj = 42; |
| 48 dynamic dyn = 42; | 46 dynamic dyn = 42; |
| 49 int i = 42; | 47 int i = 42; |
| 50 | 48 |
| 51 // Check the boolean conversion of the condition. | 49 // Check the boolean conversion of the condition. |
| 52 print((/*severe:STATIC_TYPE_ERROR*/i) ? false : true); | 50 print((/*severe:STATIC_TYPE_ERROR*/i) ? false : true); |
| 53 print((/*info:DOWN_CAST_IMPLICIT*/obj) ? false : true); | 51 print((/*info:DOWN_CAST_IMPLICIT*/obj) ? false : true); |
| (...skipping 2508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2562 | 2560 |
| 2563 baz1() sync* { yield* (/*info:DYNAMIC_CAST*/x); } | 2561 baz1() sync* { yield* (/*info:DYNAMIC_CAST*/x); } |
| 2564 Iterable baz2() sync* { yield* (/*info:DYNAMIC_CAST*/x); } | 2562 Iterable baz2() sync* { yield* (/*info:DYNAMIC_CAST*/x); } |
| 2565 Iterable<int> baz3() sync* { yield* (/*warning:DOWN_CAST_COMPOSITE*/x);
} | 2563 Iterable<int> baz3() sync* { yield* (/*warning:DOWN_CAST_COMPOSITE*/x);
} |
| 2566 Iterable<int> baz4() sync* { yield* new Iterable<int>(); } | 2564 Iterable<int> baz4() sync* { yield* new Iterable<int>(); } |
| 2567 Iterable<int> baz5() sync* { yield* (/*info:INFERRED_TYPE_ALLOCATION*/ne
w Iterable()); } | 2565 Iterable<int> baz5() sync* { yield* (/*info:INFERRED_TYPE_ALLOCATION*/ne
w Iterable()); } |
| 2568 ''' | 2566 ''' |
| 2569 }); | 2567 }); |
| 2570 }); | 2568 }); |
| 2571 } | 2569 } |
| OLD | NEW |