mirror of
https://github.com/dart-lang/sdk
synced 2024-11-05 18:22:09 +00:00
a38e265f04
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>
46 lines
1.5 KiB
Dart
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);
|
|
}
|