Files
sdk/pkg/front_end/testcases/patterns/issue51489.dart
T
Chloe Stefantsova c8f07e6387 [cfe] Remove outdated null check to allow for-in pattern entries
Part of https://github.com/dart-lang/sdk/issues/49749

Closes https://github.com/dart-lang/sdk/issues/51489

Change-Id: I1e598f8742a271e63023f95122d8166204721aeb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/284920
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2023-02-26 19:13:08 +00:00

39 lines
908 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.
test1() => <dynamic, dynamic>{for (var [i] in []) i: i};
test2(dynamic x, dynamic another) => {
1: 1,
for (var [i] in x) for (var [j] in x) ...another,
};
main() {
expectEquals(
mapToString(test1()),
mapToString({}),
);
expectEquals(
mapToString(test2([], {2: 2})),
mapToString({1: 1}),
);
expectEquals(
mapToString(test2([[0], [1], [2]], {2: 2})),
mapToString({1: 1, 2: 2}),
);
}
expectEquals(x, y) {
if (x != y) {
throw "Expected '${x}' to be equal to '${y}'.";
}
}
mapToString(Map map) {
List<String> entryStrings = [for (var e in map.entries) "${e.key}:${e.value}"];
entryStrings.sort();
return "{${entryStrings.join(',')}}";
}