dart-sdk/tests/dart2js/42531_test.dart
Stephen Adams a38e265f04 Fix #42531
Bad identifier for async closure generator body names in extension methods.

Fixed: 42531
Change-Id: Ice29bb5ac03c67b1024c0fd53ffdb9b9b1d2131f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/153484
Commit-Queue: Stephen Adams <sra@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
2020-07-08 19:29:45 +00:00

46 lines
1.5 KiB
Dart

// Copyright (c) 2020, 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.
import 'package:expect/expect.dart';
// Regression test for badly named generator body.
Future<void> goo(Future Function() f) async {
Expect.equals(102, (await f()).keys.single);
Expect.equals(104, (await f()).keys.single);
}
Future<T> identity<T>(T x) async => x;
extension Gloop<T> on Map<T, List<T>> {
// An async method using a 'complex' generator type `Map<T, List<T>>`. This
// requires a separated entry and body, which requires a name, and the name
// must be legal JavaScript.
Future<Map<T, List<T>>> foo(int x) async {
var result = await identity({(x += this.length) as T: <T>[]});
return result;
}
Future<int> bar(int x) async {
// An async closure using a 'complex' generator type `Map<T, Set<T>>`. This
// requires a separated entry and body, which requires a name, and the name
// must be legal JavaScript.
await goo(() async => {(x += this.length) as T: <T>{}});
return x;
}
}
main() async {
// Test method.
Map<int, List<int>> o1 = {1: [], 2: []};
var o2 = await o1.foo(100);
var o3 = await o2.foo(100);
Expect.equals('{102: []}', '$o2');
Expect.equals('{101: []}', '$o3');
// Test closure.
Map<int, List<int>> o = {1: [], 2: []};
int x = await o.bar(100);
Expect.equals(104, x);
}