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 import "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
6 | 6 |
7 // Test that optimized '+' and slow path '+' produce the same error. | 7 // Test that optimized '+' and slow path '+' produce the same error. |
8 | 8 |
9 @NoInline() | 9 @NoInline() |
10 @AssumeDynamic() | 10 @AssumeDynamic() |
11 confuse(x) => x; | 11 confuse(x) => x; |
12 | 12 |
13 void check2(String name, name1, f1, name2, f2) { | 13 void check2(String name, name1, f1, name2, f2) { |
14 Error trap(part, f) { | 14 Error trap(part, f) { |
15 try { | 15 try { |
16 f(); | 16 f(); |
17 } catch (e) { | 17 } catch (e) { |
18 return e; | 18 return e; |
19 } | 19 } |
20 Expect.fail('should throw: $name.$part'); | 20 Expect.fail('should throw: $name.$part'); |
21 } | 21 } |
| 22 |
22 var e1 = trap(name1, f1); | 23 var e1 = trap(name1, f1); |
23 var e2 = trap(name2, f2); | 24 var e2 = trap(name2, f2); |
24 var s1 = '$e1'; | 25 var s1 = '$e1'; |
25 var s2 = '$e2'; | 26 var s2 = '$e2'; |
26 Expect.equals(s1, s2, '\n $name.$name1: "$s1"\n $name.$name2: "$s2"\n'); | 27 Expect.equals(s1, s2, '\n $name.$name1: "$s1"\n $name.$name2: "$s2"\n'); |
27 } | 28 } |
28 | 29 |
29 void check(String name, f1, f2, [f3, f4, f5, f6, f7]) { | 30 void check(String name, f1, f2, [f3, f4, f5, f6, f7]) { |
30 check2(name, 'f1', f1, 'f2', f2); | 31 check2(name, 'f1', f1, 'f2', f2); |
31 if (f3 != null) check2(name, 'f1', f1, 'f3', f3); | 32 if (f3 != null) check2(name, 'f1', f1, 'f3', f3); |
(...skipping 14 matching lines...) Expand all Loading... |
46 | 47 |
47 static f3() { | 48 static f3() { |
48 return (confuse(1) as int) + confuse(null); | 49 return (confuse(1) as int) + confuse(null); |
49 } | 50 } |
50 | 51 |
51 static f4() { | 52 static f4() { |
52 return (confuse(1) as int) + null; | 53 return (confuse(1) as int) + null; |
53 } | 54 } |
54 | 55 |
55 static f5() { | 56 static f5() { |
56 var a = confuse(true) ? 1 : 2; // Small int with unknown value. | 57 var a = confuse(true) ? 1 : 2; // Small int with unknown value. |
57 return a + confuse(null); | 58 return a + confuse(null); |
58 } | 59 } |
59 | 60 |
60 static f6() { | 61 static f6() { |
61 var a = confuse(true) ? 1 : 2; // Small int with unknown value. | 62 var a = confuse(true) ? 1 : 2; // Small int with unknown value. |
62 return a + null; | 63 return a + null; |
63 } | 64 } |
64 | 65 |
65 static f7() { | 66 static f7() { |
66 return 1 + null; | 67 return 1 + null; |
67 } | 68 } |
68 | 69 |
69 static test() { | 70 static test() { |
70 check('IntPlusNull', f1, f2, f3, f4, f5, f6, f7); | 71 check('IntPlusNull', f1, f2, f3, f4, f5, f6, f7); |
71 } | 72 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 class IntPlusString { | 111 class IntPlusString { |
111 static f1() { | 112 static f1() { |
112 return confuse(1) + confuse('a'); | 113 return confuse(1) + confuse('a'); |
113 } | 114 } |
114 | 115 |
115 static f2() { | 116 static f2() { |
116 return confuse(1) + 'a'; | 117 return confuse(1) + 'a'; |
117 } | 118 } |
118 | 119 |
119 static f3() { | 120 static f3() { |
120 var a = confuse(true) ? 1 : 2; // Small int with unknown value. | 121 var a = confuse(true) ? 1 : 2; // Small int with unknown value. |
121 return a + confuse('a'); | 122 return a + confuse('a'); |
122 } | 123 } |
123 | 124 |
124 static f4() { | 125 static f4() { |
125 return (confuse(1) as int) + confuse('a'); | 126 return (confuse(1) as int) + confuse('a'); |
126 } | 127 } |
127 | 128 |
128 static f5() { | 129 static f5() { |
129 return (confuse(1) as int) + 'a'; | 130 return (confuse(1) as int) + 'a'; |
130 } | 131 } |
131 | 132 |
132 static f6() { | 133 static f6() { |
133 var a = confuse(true) ? 1 : 2; // Small int with unknown value. | 134 var a = confuse(true) ? 1 : 2; // Small int with unknown value. |
134 return a + 'a'; | 135 return a + 'a'; |
135 } | 136 } |
136 | 137 |
137 static f7() { | 138 static f7() { |
138 return 1 + 'a'; | 139 return 1 + 'a'; |
139 } | 140 } |
140 | 141 |
141 static test() { | 142 static test() { |
142 check('IntPlusString', f1, f2, f3, f4, f5, f6, f7); | 143 check('IntPlusString', f1, f2, f3, f4, f5, f6, f7); |
143 } | 144 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 check('StringPlusInt', f1, f2, f3, f4, f5, f6, f7); | 179 check('StringPlusInt', f1, f2, f3, f4, f5, f6, f7); |
179 } | 180 } |
180 } | 181 } |
181 | 182 |
182 main() { | 183 main() { |
183 IntPlusNull.test(); | 184 IntPlusNull.test(); |
184 StringPlusNull.test(); | 185 StringPlusNull.test(); |
185 IntPlusString.test(); | 186 IntPlusString.test(); |
186 StringPlusInt.test(); | 187 StringPlusInt.test(); |
187 } | 188 } |
OLD | NEW |