Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(666)

Side by Side Diff: tests/language/switch_int_double_test.dart

Issue 23640004: Require case expressions to be compile-time constants (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tests/co19/co19-runtime.status ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 }
OLDNEW
« no previous file with comments | « tests/co19/co19-runtime.status ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698