Skip to content

Commit 428cb00

Browse files
include type parameters on generic sync/async functions
fixes #538 [email protected] Review URL: https://codereview.chromium.org/1935823002 .
1 parent b2c0a74 commit 428cb00

File tree

4 files changed

+51
-0
lines changed

4 files changed

+51
-0
lines changed

pkg/dev_compiler/lib/src/compiler/code_generator.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1881,6 +1881,7 @@ class CodeGenerator extends GeneralizingAstVisitor
18811881
new JS.Block([
18821882
_emitGeneratorFunctionBody(element, parameters, body).toReturn()
18831883
]),
1884+
typeParams: _emitTypeFormals(type.typeFormals),
18841885
returnType: emitTypeRef(type.returnType));
18851886
}
18861887

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import "package:expect/expect.dart";
6+
7+
import 'dart:async';
8+
9+
Stream/*<T>*/ foo/*<T>*/(/*=T*/ x) async* {
10+
for (int i = 0; i < 3; i++) {
11+
yield x;
12+
}
13+
}
14+
15+
main() async {
16+
await for (var x in foo/*<int>*/(1)) {
17+
Expect.equals(1, x);
18+
}
19+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import "package:expect/expect.dart";
6+
7+
import 'dart:async';
8+
9+
Future/*<T>*/ foo/*<T>*/(/*=T*/ x) async => x;
10+
11+
main() async {
12+
Expect.equals(1, await foo/*<int>*/(1));
13+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import "package:expect/expect.dart";
6+
7+
8+
Iterable/*<T>*/ foo/*<T>*/(/*=T*/ x) sync* {
9+
for (int i = 0; i < 3; i++) {
10+
yield x;
11+
}
12+
}
13+
14+
main() {
15+
for (var x in foo/*<int>*/(1)) {
16+
Expect.equals(1, x);
17+
}
18+
}

0 commit comments

Comments
 (0)