Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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("compiler_helper.dart"); | 5 #import("compiler_helper.dart"); |
| 6 | 6 |
| 7 const int REMOVED = 0; | 7 const int REMOVED = 0; |
| 8 const int ABOVE_ZERO = 1; | 8 const int ABOVE_ZERO = 1; |
| 9 const int BELOW_LENGTH = 2; | 9 const int BELOW_LENGTH = 2; |
| 10 const int KEPT = 3; | 10 const int KEPT = 3; |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 121 } | 121 } |
| 122 """, | 122 """, |
| 123 ONE_ZERO_CHECK, | 123 ONE_ZERO_CHECK, |
| 124 | 124 |
| 125 """ | 125 """ |
| 126 main(value) { | 126 main(value) { |
| 127 var a = new List(); | 127 var a = new List(); |
| 128 return a[1] + a[0]; | 128 return a[1] + a[0]; |
| 129 } | 129 } |
| 130 """, | 130 """, |
| 131 ONE_CHECK | 131 ONE_CHECK, |
| 132 | |
| 133 """ | |
| 134 main() { | |
| 135 var a = new List(); | |
| 136 var sum = 0; | |
| 137 for (int i = 0; i <= a.length - 1; i++) { | |
| 138 sum += a[i]; | |
| 139 } | |
| 140 return sum; | |
| 141 } | |
| 142 """, | |
| 143 REMOVED, | |
| 144 | |
| 145 """ | |
| 146 main() { | |
| 147 var a = new List(); | |
| 148 var sum = 0; | |
| 149 for (int i = a.length - 1; i >=0; i--) { | |
| 150 sum += a[i]; | |
| 151 } | |
| 152 return sum; | |
| 153 } | |
| 154 """, | |
| 155 REMOVED, | |
| 156 | |
| 157 """ | |
| 158 main(value) { | |
| 159 // Force [value] to be an int. | |
|
Søren Gjesse
2012/10/02 08:07:20
I don't understand how this forces value to be an
ngeoffray
2012/10/02 16:03:09
It makes the type guard computation want value to
| |
| 160 int sum = 0; | |
| 161 for (int i = 0; i < 42; i++) sum += (value & 4); | |
| 162 var a = new List(); | |
| 163 if (value > a.length - 1) return; | |
| 164 if (value < 0) return; | |
| 165 return a[value]; | |
| 166 } | |
| 167 """, | |
| 168 REMOVED, | |
| 169 | |
| 170 """ | |
| 171 main(value) { | |
| 172 // Force [value] to be an int. | |
| 173 int sum = 0; | |
| 174 for (int i = 0; i < 42; i++) sum += (value & 4); | |
| 175 var a = new List(); | |
| 176 if (value <= a.length - 1) { | |
| 177 if (value >= 0) { | |
| 178 return a[value]; | |
| 179 } | |
| 180 } | |
| 181 } | |
| 182 """, | |
| 183 REMOVED, | |
| 184 """ | |
| 185 main(value) { | |
| 186 // Force [value] to be an int. | |
| 187 int sum = 0; | |
| 188 for (int i = 0; i < 42; i++) sum += (value & 4); | |
| 189 var a = new List(); | |
| 190 if (value >= a.length) return; | |
| 191 if (value <= -1) return; | |
| 192 return a[value]; | |
| 193 } | |
| 194 """, | |
| 195 REMOVED, | |
| 132 ]; | 196 ]; |
| 133 | 197 |
| 134 expect(String code, int kind) { | 198 expect(String code, int kind) { |
| 135 String generated = compile(code); | 199 String generated = compile(code); |
| 136 switch (kind) { | 200 switch (kind) { |
| 137 case REMOVED: | 201 case REMOVED: |
| 138 Expect.isTrue(!generated.contains('ioore')); | 202 Expect.isTrue(!generated.contains('ioore')); |
| 139 break; | 203 break; |
| 140 | 204 |
| 141 case ABOVE_ZERO: | 205 case ABOVE_ZERO: |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 166 break; | 230 break; |
| 167 } | 231 } |
| 168 } | 232 } |
| 169 | 233 |
| 170 | 234 |
| 171 main() { | 235 main() { |
| 172 for (int i = 0; i < TESTS.length; i += 2) { | 236 for (int i = 0; i < TESTS.length; i += 2) { |
| 173 expect(TESTS[i], TESTS[i + 1]); | 237 expect(TESTS[i], TESTS[i + 1]); |
| 174 } | 238 } |
| 175 } | 239 } |
| OLD | NEW |