Files
sdk/tests/language/switch_int_double_test.dart
T
hausner@google.com 3e9467672f Require case expressions to be compile-time constants
Remove legacy semantics in switch statement compilation.

Still to be added: analysis that all case expressions are
of the same type.

R=regis@google.com

Review URL: https://codereview.chromium.org//23640004

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@26749 260f80e4-7a28-3924-810f-c04153c831b5
2013-08-27 23:07:59 +00:00

27 lines
738 B
Dart

// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Test reporting a compile-time error if case expressions do not all have
// the same type.
import "package:expect/expect.dart";
void main() {
Expect.equals(100, test(1.0));
Expect.equals(75, test(0.75));
Expect.equals(null, test(0.5));
}
int test(num ratio) {
switch (ratio) {
case 0.75:
return 75;
case 1.0:
return 100;
case 2: /// 01: compile-time error
return 200; /// 01: continued
case 'foo': /// 02: compile-time error
return 400; /// 02: continued
}
}