Files
sdk/tests/language_2/const/switch2_test.dart
T
Johnni Winther 2a1224f3b5 [cfe] Check primitive equals in legacy libraries
This enables the check for primitive equals in switch cases in
legacy libraries.

Change-Id: Iddc464f39525d5167a5c6e8c40c95acc3c245d76
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/231701
Reviewed-by: Joshua Litt <joshualitt@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2022-02-10 22:13:14 +00:00

26 lines
773 B
Dart

// Copyright (c) 2014, 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.
// @dart = 2.9
import 'package:expect/expect.dart';
int main() {
var a = [1, 2, 3][2];
switch (a) {
// ^
// [analyzer] COMPILE_TIME_ERROR.SWITCH_EXPRESSION_NOT_ASSIGNABLE
case 0.0:
// ^
// [cfe] Case expression '0.0' does not have a primitive operator '=='.
// [cfe] Type 'int' of the switch expression isn't assignable to the type 'double' of this case expression.
print("illegal");
break;
case 1:
// ^
// [analyzer] COMPILE_TIME_ERROR.INCONSISTENT_CASE_EXPRESSION_TYPES
print("OK");
}
}