fc1b1ecc71
Change-Id: Idbcc965a27e9ffeedf5e0a1068b019de4193070f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/127745 Commit-Queue: Bob Nystrom <rnystrom@google.com> Reviewed-by: Alexander Thomas <athom@google.com>
41 lines
951 B
Dart
41 lines
951 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 or are of type double.
|
|
|
|
import "package:expect/expect.dart";
|
|
|
|
void main() {
|
|
Expect.equals("IV", caesarSays(4));
|
|
Expect.equals(null, caesarSays(2));
|
|
Expect.equals(null, archimedesSays(3.14));
|
|
}
|
|
|
|
caesarSays(n) {
|
|
switch (n) {
|
|
case 1:
|
|
return "I";
|
|
case 4:
|
|
return "IV";
|
|
case "M":
|
|
// ^^^
|
|
// [analyzer] COMPILE_TIME_ERROR.INCONSISTENT_CASE_EXPRESSION_TYPES
|
|
return 1000;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
archimedesSays(n) {
|
|
switch (n) {
|
|
//^^^^^^
|
|
// [analyzer] COMPILE_TIME_ERROR.CASE_EXPRESSION_TYPE_IMPLEMENTS_EQUALS
|
|
case 3.14:
|
|
return "Pi";
|
|
case 2.71828:
|
|
return "Huh?";
|
|
}
|
|
return null;
|
|
}
|