// 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 goo(Future Function() f) async { Expect.equals(102, (await f()).keys.single); Expect.equals(104, (await f()).keys.single); } Future identity(T x) async => x; extension Gloop on Map> { // An async method using a 'complex' generator type `Map>`. This // requires a separated entry and body, which requires a name, and the name // must be legal JavaScript. Future>> foo(int x) async { var result = await identity({(x += this.length) as T: []}); return result; } Future bar(int x) async { // An async closure using a 'complex' generator type `Map>`. 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: {}}); return x; } } main() async { // Test method. Map> 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> o = {1: [], 2: []}; int x = await o.bar(100); Expect.equals(104, x); }