| 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 reporting a compile-time error if case expressions do not all have |
| 6 // the same type or are of type double. |
| 7 |
| 8 import "package:expect/expect.dart"; |
| 9 |
| 10 void main() { |
| 11 Expect.equals("IV", caesarSays(4)); |
| 12 Expect.equals(null, caesarSays(2)); |
| 13 Expect.equals(null, archimedesSays(3.14)); |
| 14 } |
| 15 |
| 16 caesarSays(n) { |
| 17 switch (n) { |
| 18 case 1: |
| 19 return "I"; |
| 20 case 4: |
| 21 return "IV"; |
| 22 case "M": /// 01: compile-time error |
| 23 return 1000; /// 01: continued |
| 24 } |
| 25 return null; |
| 26 } |
| 27 |
| 28 archimedesSays(n) { |
| 29 switch (n) { /// 02: continued |
| 30 case 3.14: /// 02: compile-time error |
| 31 return "Pi"; /// 02: continued |
| 32 case 2.71828: /// 02: continued |
| 33 return "Huh?"; /// 02: continued |
| 34 } /// 02: continued |
| 35 return null; |
| 36 } |
| OLD | NEW |