Chromium Code Reviews| OLD | NEW | 
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | |
| 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. | |
| 4 | |
| 5 // Test least upper bound through type checking of conditionals. | |
| 6 | |
| 7 class N<T> { | |
| 8 T get n => null; | |
| 9 } | |
| 10 | |
| 11 class C1<T> extends N<N<C1<T>>> { | |
| 12 T get c1 => null; | |
| 13 } | |
| 14 | |
| 15 class C2<T> extends N<N<C2<N<C2<T>>>>> { | |
| 16 T get c2 => null; | |
| 17 } | |
| 18 | |
| 19 /** | |
| 20 * Test that we don't try to find the least upper bound by applying the | |
| 21 * algorithm for finding the most specific common declaration recursively on | |
| 22 * type arguments. | |
| 23 * | |
| 24 * For C1<int> and N<C1<String>> this would result in this infinite chain of | |
| 25 * computations: | |
| 26 * | |
| 27 * lub(C1<int>,N<C1<String>>)=lub(N<N<C1<int>>>,N<C1<String>>) | |
| 
 
karlklose
2013/11/21 13:29:10
Please add space between arguments and around '='.
 
Johnni Winther
2013/11/25 13:58:27
Done.
 
 | |
| 28 * => | |
| 29 * lub(N<C1<int>>,C1<String>)=lub(N<C1<int>>,N<N<C1<String>>>) | |
| 30 * => | |
| 31 * lub(C1<int>,N<C1<String>>)=lub(N<N<C1<int>>>,N<C1<String>>>) | |
| 32 * => ... | |
| 33 */ | |
| 34 void testC1(bool z, C1<int> a, N<C1<String>> b) { | |
| 35 if (z) { | |
| 
 
karlklose
2013/11/21 13:29:10
This guard against dead-code elimination is brittl
 
Johnni Winther
2013/11/25 13:58:27
It doesn't really matter. I don't want to run it,
 
 | |
| 36 // The least upper bound of C1<int> and N<C1<String>> is Object since the | |
| 37 // supertypes are | |
| 38 // {C1<int>, N<N<C1<int>>>, Object} for C1<int> and | |
| 39 // {N<C1<String>>, Object} for N<C1<String>> and | |
| 40 // Object is the most specific type in the intersection of the supertypes. | |
| 41 | |
| 42 // Is least upper bound dynamic? | |
| 43 (z ? a : b).z; /// 01: static type warning | |
| 44 // Is least upper bound N<...> ? | |
| 45 (z ? a : b).n; /// 02: static type warning | |
| 46 // Is least upper bound C1<...> ? | |
| 47 (z ? a : b).c1; /// 03: static type warning | |
| 48 // Is least upper bound N<dynamic> ? | |
| 49 (z ? a : b).n.z; /// 04: static type warning | |
| 50 // Is least upper bound N<N<...>> ? | |
| 51 (z ? a : b).n.n; /// 05: static type warning | |
| 52 // Is least upper bound N<C1<...>> ? | |
| 53 (z ? a : b).n.c1; /// 06: static type warning | |
| 54 } | |
| 55 } | |
| 56 | |
| 57 /** | |
| 58 * Test that we don't try to find the least upper bound by applying the | |
| 59 * algorithm for finding the most specific common declaration recursively on | |
| 60 * type arguments. | |
| 61 * | |
| 62 * For C1<int> and N<C1<String>> this would result in this infinite and | |
| 63 * expanding chain of computations: | |
| 64 * | |
| 65 * lub(C2<int>,N<C2<String>>)=lub(N<N<C2<N<C2<int>>>>>,N<C2<String>>) | |
| 66 * => | |
| 67 * lub(N<C2<N<C2<int>>>>,C2<String>)= | |
| 68 * lub(N<C2<N<C2<int>>>>,N<N<C2<N<C2<String>>>>>) | |
| 69 * => | |
| 70 * lub(C2<N<C2<int>>>,N<C2<N<C2<String>>>>)= | |
| 71 lub(N<N<C2<N<C2<int>>>>>,N<C2<N<C2<String>>>>>) | |
| 72 * => ... | |
| 73 */ | |
| 74 | |
| 75 void testC2(bool z, C2<int> a, N<C2<String>> b) { | |
| 76 if (z) { | |
| 77 // The least upper bound of C2<int> and N<C2<String>> is Object since the | |
| 78 // supertypes are | |
| 79 // {C2<int>, N<N<C2<N<C2<int>>>>>, Object} for C1<int> and | |
| 80 // {N<C2<String>>, Object} for N<C1<String>> and | |
| 81 // Object is the most specific type in the intersection of the supertypes. | |
| 82 | |
| 83 // Is least upper bound dynamic? | |
| 84 (z ? a : b).z; /// 07: static type warning | |
| 85 // Is least upper bound N<...> ? | |
| 86 (z ? a : b).n; /// 08: static type warning | |
| 87 // Is least upper bound C2<...> ? | |
| 88 (z ? a : b).c2; /// 09: static type warning | |
| 89 // Is least upper bound N<dynamic> ? | |
| 90 (z ? a : b).n.z; /// 10: static type warning | |
| 91 // Is least upper bound N<N<...>> ? | |
| 92 (z ? a : b).n.n; /// 11: static type warning | |
| 93 // Is least upper bound N<C2<...>> ? | |
| 94 (z ? a : b).n.c2; /// 12: static type warning | |
| 95 } | |
| 96 } | |
| 97 | |
| 98 void main() { | |
| 99 testC1(false, null, null); | |
| 100 testC2(false, null, null); | |
| 101 } | |
| OLD | NEW |