Chromium Code Reviews| 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 10 matching lines...) Expand all Loading... | |
| 21 static int compare(Comparable a, Comparable b) => a.compareTo(b); | 21 static int compare(Comparable a, Comparable b) => a.compareTo(b); |
| 22 } | 22 } |
| 23 typedef int Comparator<T>(T a, T b); | 23 typedef int Comparator<T>(T a, T b); |
| 24 | 24 |
| 25 typedef bool _Predicate<T>(T value); | 25 typedef bool _Predicate<T>(T value); |
| 26 | 26 |
| 27 class SplayTreeMap<K, V> { | 27 class SplayTreeMap<K, V> { |
| 28 Comparator<K> _comparator; | 28 Comparator<K> _comparator; |
| 29 _Predicate _validKey; | 29 _Predicate _validKey; |
| 30 | 30 |
| 31 // TODO(rnystrom): Initializing _comparator should have a cast, since | 31 // The warning on assigning to _comparator is legitimate. Since K has |
| 32 // K may not always be Comparable. It doesn't currently get one | 32 // no bound, all we know is that it's object. _comparator's function |
| 33 // because we're using the spec's LUB on function types, which isn't | 33 // type is effectively: (Object, Object) -> int |
| 34 // sound. | 34 // We are assigning it a fn of type: (Comparable, Comparable) -> int |
| 35 // There's no telling if that will work. For example, consider: | |
| 36 // | |
| 37 // new SplayTreeMap<Uri>(); | |
| 38 // | |
| 39 // This would end up calling .compareTo() on a Uri, which doesn't | |
| 40 // define that since it doesn't implement Comparable. | |
| 35 SplayTreeMap([int compare(K key1, K key2), | 41 SplayTreeMap([int compare(K key1, K key2), |
| 36 bool isValidKey(potentialKey)]) | 42 bool isValidKey(potentialKey)]) |
| 37 : _comparator = (compare == null) ? Comparable.compare : compare, | 43 : _comparator = /*warning:FIELD_INITIALIZER_NOT_ASSIGNABLE*/(compare == null) ? Comparable.compare : compare, |
| 38 _validKey = (isValidKey != null) ? isValidKey : ((v) => true) { | 44 _validKey = (isValidKey != null) ? isValidKey : ((v) => true) { |
| 39 _Predicate<Object> v = /*warning:DOWN_CAST_COMPOSITE*/(isValidKey != null) | 45 _Predicate<Object> v = (isValidKey != null) |
|
Leaf
2016/03/22 00:02:20
\o/
| |
| 40 ? isValidKey : (/*info:INFERRED_TYPE_CLOSURE */(_) => true); | 46 ? isValidKey : (/*info:INFERRED_TYPE_CLOSURE*/(_) => true); |
| 41 | 47 |
| 42 v = (isValidKey != null) | 48 v = (isValidKey != null) |
| 43 ? v : (/*info:INFERRED_TYPE_CLOSURE*/(_) => true); | 49 ? v : (/*info:INFERRED_TYPE_CLOSURE*/(_) => true); |
| 44 } | 50 } |
| 45 } | 51 } |
| 46 void main() { | 52 void main() { |
| 47 Object obj = 42; | 53 Object obj = 42; |
| 48 dynamic dyn = 42; | 54 dynamic dyn = 42; |
| 49 int i = 42; | 55 int i = 42; |
| 50 | 56 |
| (...skipping 2855 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2906 | 2912 |
| 2907 baz1() sync* { yield* /*info:DYNAMIC_CAST*/x; } | 2913 baz1() sync* { yield* /*info:DYNAMIC_CAST*/x; } |
| 2908 Iterable baz2() sync* { yield* /*info:DYNAMIC_CAST*/x; } | 2914 Iterable baz2() sync* { yield* /*info:DYNAMIC_CAST*/x; } |
| 2909 Iterable<int> baz3() sync* { yield* /*warning:DOWN_CAST_COMPOSITE*/x; } | 2915 Iterable<int> baz3() sync* { yield* /*warning:DOWN_CAST_COMPOSITE*/x; } |
| 2910 Iterable<int> baz4() sync* { yield* bar3(); } | 2916 Iterable<int> baz4() sync* { yield* bar3(); } |
| 2911 Iterable<int> baz5() sync* { yield* /*info:INFERRED_TYPE_ALLOCATION*/new List(); } | 2917 Iterable<int> baz5() sync* { yield* /*info:INFERRED_TYPE_ALLOCATION*/new List(); } |
| 2912 '''); | 2918 '''); |
| 2913 }); | 2919 }); |
| 2914 }); | 2920 }); |
| 2915 } | 2921 } |
| OLD | NEW |