Files
sdk/tests/language/patterns/int_to_double_error_test.dart
T
Sergey G. Grekhov 82b78916fd [tests] Remove obsolete Dart 3.0 experiments from language tests
Change-Id: If31c487e3ebe2c1ae847aff7c8994580b8b6f2f6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/309660
Reviewed-by: Alexander Thomas <athom@google.com>
Commit-Queue: Alexander Thomas <athom@google.com>
2023-06-15 08:26:27 +00:00

32 lines
1.2 KiB
Dart

// Copyright (c) 2023, 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 where a pattern does and does not create a context type that leads to
/// int-to-double conversion.
import "package:expect/expect.dart";
main() {
// No coercion during runtime destructuring.
(int, int) record = (1, 2);
var (double x, double y) = record;
// ^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.PATTERN_TYPE_MISMATCH_IN_IRREFUTABLE_CONTEXT
// ^
// [cfe] The matched value of type 'int' isn't assignable to the required type 'double'.
// ^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.PATTERN_TYPE_MISMATCH_IN_IRREFUTABLE_CONTEXT
// ^
// [cfe] The matched value of type 'int' isn't assignable to the required type 'double'.
// Non-exhaustive since double case doesn't cover uncoerced int type.
var result = switch (123) {
// ^^^^^^
// [analyzer] COMPILE_TIME_ERROR.NON_EXHAUSTIVE_SWITCH_EXPRESSION
// ^
// [cfe] The type 'int' is not exhaustively matched by the switch cases since it doesn't match 'int()'.
double d => 'wrong'
};
}