Files
sdk/tests/language/patterns/nullable_object_pattern_error_test.dart
T
Paul Berry 94862482d2 Test object pattern behavior with nullable and potentially nullable types.
Change-Id: Ic9075cdbb0aedd17a00d500c44dc33e1516b940b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/300323
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Bob Nystrom <rnystrom@google.com>
2023-05-02 18:01:53 +00:00

35 lines
1008 B
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 that the appropriate errors are generated if a nullable type is used in
/// an object pattern.
typedef A = int?;
void nullableWithField(x) {
// This is an error because `isEven` can't be called on `int?`.
switch (x) {
case A(isEven: true):
// ^
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
// ^
// [cfe] The getter 'isEven' isn't defined for the class 'int?'.
break;
}
}
void potentiallyNullableWithField<T extends int?>(x) {
// This is an error because `isEven` can't be called on `int?`.
switch (x) {
case T(isEven: true):
// ^
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
// ^
// [cfe] The getter 'isEven' isn't defined for the class 'int?'.
break;
}
}
main() {}