Files
sdk/tests/language/null_aware_elements/warnings_simple_test.dart
T
Robert Nystrom 159de518e2 Reformat tests/language/m-p using the 3.8 style.
Change-Id: I28f61e1e85408acc5403bfe95f360df4c7cb5ece
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/425151
Auto-Submit: Bob Nystrom <rnystrom@google.com>
Reviewed-by: Lasse Nielsen <lrn@google.com>
Commit-Queue: Lasse Nielsen <lrn@google.com>
2025-04-29 07:30:40 -07:00

39 lines
1.1 KiB
Dart

// Copyright (c) 2024, 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.
// SharedOptions=--enable-experiment=null-aware-elements
import 'package:expect/expect.dart';
List<int> testList(int x) {
return <int>[?x];
// ^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
}
Set<int> testSet(int x) {
return <int>{?x};
// ^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
}
Map<int, String> testMapKey(int x) {
return <int, String>{?x: ""};
// ^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
}
Map<String, int> testMapValue(int x) {
return <String, int>{"": ?x};
// ^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
}
main() {
Expect.listEquals(testList(0), <int>[0]);
Expect.setEquals(testSet(0), <int>{0});
Expect.mapEquals(testMapKey(0), <int, String>{0: ""});
Expect.mapEquals(testMapValue(0), <String, int>{"": 0});
}