OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 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 | 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 // Test that double literals with no fractional part is not treated as having | 5 // Test reporting a compile-time error if case expressions do not all have |
6 // static type int. | 6 // the same type. |
7 | 7 |
8 import "package:expect/expect.dart"; | 8 import "package:expect/expect.dart"; |
9 | 9 |
10 void main() { | 10 void main() { |
11 Expect.equals(100, test(1.0)); | 11 Expect.equals(100, test(1.0)); |
12 Expect.equals(75, test(0.75)); | 12 Expect.equals(75, test(0.75)); |
13 Expect.equals(null, test(0.5)); | 13 Expect.equals(null, test(0.5)); |
14 } | 14 } |
15 | 15 |
16 int test(num ratio) { | 16 int test(num ratio) { |
17 switch (ratio) { | 17 switch (ratio) { |
18 case 0.75: | 18 case 0.75: |
19 return 75; | 19 return 75; |
20 case 1.0: | 20 case 1.0: |
21 return 100; | 21 return 100; |
22 case 2: /// 01: compile-time error | 22 case 2: /// 01: compile-time error |
23 return 200; /// 01: continued | 23 return 200; /// 01: continued |
24 case 'foo': /// 02: compile-time error | 24 case 'foo': /// 02: compile-time error |
25 return 400; /// 02: continued | 25 return 400; /// 02: continued |
26 } | 26 } |
27 } | 27 } |
OLD | NEW |