Skip to content

Commit 4352f10

Browse files
chloestefantsovaCommit Queue
authored and
Commit Queue
committed
[cfe] Implement spec update on generator element type
The update can be found here: https://github.com/dart-lang/language/pull/3218/files Closes #53052 Change-Id: I08146a6ca09667cc5e0ebcd564e60f454d03a468 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/320763 Reviewed-by: Johnni Winther <[email protected]> Commit-Queue: Chloe Stefantsova <[email protected]>
1 parent c867de3 commit 4352f10

11 files changed

+381
-2
lines changed

pkg/front_end/lib/src/fasta/type_inference/closure_context.dart

+6-2
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,16 @@ abstract class ClosureContext {
5353
if (isGenerator) {
5454
if (isAsync) {
5555
DartType yieldContext = inferrer.getTypeArgumentOf(
56-
returnContext, inferrer.coreTypes.streamClass);
56+
inferrer.typeSchemaEnvironment.getUnionFreeType(returnContext,
57+
isNonNullableByDefault: inferrer.isNonNullableByDefault),
58+
inferrer.coreTypes.streamClass);
5759
return new _AsyncStarClosureContext(
5860
inferrer, yieldContext, declaredReturnType, needToInferReturnType);
5961
} else {
6062
DartType yieldContext = inferrer.getTypeArgumentOf(
61-
returnContext, inferrer.coreTypes.iterableClass);
63+
inferrer.typeSchemaEnvironment.getUnionFreeType(returnContext,
64+
isNonNullableByDefault: inferrer.isNonNullableByDefault),
65+
inferrer.coreTypes.iterableClass);
6266
return new _SyncStarClosureContext(
6367
inferrer, yieldContext, declaredReturnType, needToInferReturnType);
6468
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright (c) 2023, 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 'dart:async';
6+
7+
FutureOr<Iterable<int>> f() sync* {
8+
yield 'Hello!' as dynamic;
9+
}
10+
11+
FutureOr<Stream<int>> g() async* {
12+
yield* 'Hello!' as dynamic;
13+
}
14+
15+
main() async {
16+
var iterable = f();
17+
if (iterable is Future<Object?>) return;
18+
expectThrows(() { int i = iterable.first; });
19+
20+
var stream = g();
21+
if (stream is Future<Object?>) return;
22+
await expectAsyncThrows(() async { int i = await stream.first; });
23+
}
24+
25+
expectThrows(f) {
26+
bool hasThrown = true;
27+
try {
28+
f();
29+
hasThrown = false;
30+
} catch(e) {}
31+
if (!hasThrown) {
32+
throw "Expected the function to throw.";
33+
}
34+
}
35+
36+
expectAsyncThrows(f) async {
37+
bool hasThrown = true;
38+
try {
39+
await f();
40+
hasThrown = false;
41+
} catch(e) {}
42+
if (!hasThrown) {
43+
throw "Expected the function to throw.";
44+
}
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
library;
2+
import self as self;
3+
import "dart:core" as core;
4+
import "dart:async" as asy;
5+
6+
import "dart:async";
7+
8+
static method f() → FutureOr<core::Iterable<core::int>> sync* {
9+
yield("Hello!" as dynamic) as{TypeError,ForDynamic} core::int;
10+
}
11+
static method g() → FutureOr<asy::Stream<core::int>> async* {
12+
yield*("Hello!" as dynamic) as{TypeError,ForDynamic} asy::Stream<core::int>;
13+
}
14+
static method main() → dynamic async /* futureValueType= dynamic */ {
15+
FutureOr<core::Iterable<core::int>>iterable = self::f();
16+
if(iterable is asy::Future<core::Object?>)
17+
return;
18+
self::expectThrows(() → Null {
19+
core::int i = iterable{core::Iterable<core::int>}.{core::Iterable::first}{core::int};
20+
});
21+
FutureOr<asy::Stream<core::int>>stream = self::g();
22+
if(stream is asy::Future<core::Object?>)
23+
return;
24+
await self::expectAsyncThrows(() → asy::Future<Null> async /* futureValueType= Null */ {
25+
core::int i = await stream{asy::Stream<core::int>}.{asy::Stream::first}{asy::Future<core::int>};
26+
}) /* runtimeCheckType= asy::Future<dynamic> */ ;
27+
}
28+
static method expectThrows(dynamic f) → dynamic {
29+
core::bool hasThrown = true;
30+
try {
31+
f{dynamic}.call();
32+
hasThrown = false;
33+
}
34+
on core::Object catch(final core::Object e) {
35+
}
36+
if(!hasThrown) {
37+
throw "Expected the function to throw.";
38+
}
39+
}
40+
static method expectAsyncThrows(dynamic f) → dynamic async /* futureValueType= dynamic */ {
41+
core::bool hasThrown = true;
42+
try {
43+
await f{dynamic}.call() /* runtimeCheckType= asy::Future<dynamic> */ ;
44+
hasThrown = false;
45+
}
46+
on core::Object catch(final core::Object e) {
47+
}
48+
if(!hasThrown) {
49+
throw "Expected the function to throw.";
50+
}
51+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
library;
2+
import self as self;
3+
import "dart:core" as core;
4+
import "dart:async" as asy;
5+
6+
import "dart:async";
7+
8+
static method f() → FutureOr<core::Iterable<core::int>> sync* {
9+
yield("Hello!" as dynamic) as{TypeError,ForDynamic} core::int;
10+
}
11+
static method g() → FutureOr<asy::Stream<core::int>> async* {
12+
yield*("Hello!" as dynamic) as{TypeError,ForDynamic} asy::Stream<core::int>;
13+
}
14+
static method main() → dynamic async /* futureValueType= dynamic */ {
15+
FutureOr<core::Iterable<core::int>>iterable = self::f();
16+
if(iterable is asy::Future<core::Object?>)
17+
return;
18+
self::expectThrows(() → Null {
19+
core::int i = iterable{core::Iterable<core::int>}.{core::Iterable::first}{core::int};
20+
});
21+
FutureOr<asy::Stream<core::int>>stream = self::g();
22+
if(stream is asy::Future<core::Object?>)
23+
return;
24+
await self::expectAsyncThrows(() → asy::Future<Null> async /* futureValueType= Null */ {
25+
core::int i = await stream{asy::Stream<core::int>}.{asy::Stream::first}{asy::Future<core::int>};
26+
}) /* runtimeCheckType= asy::Future<dynamic> */ ;
27+
}
28+
static method expectThrows(dynamic f) → dynamic {
29+
core::bool hasThrown = true;
30+
try {
31+
f{dynamic}.call();
32+
hasThrown = false;
33+
}
34+
on core::Object catch(final core::Object e) {
35+
}
36+
if(!hasThrown) {
37+
throw "Expected the function to throw.";
38+
}
39+
}
40+
static method expectAsyncThrows(dynamic f) → dynamic async /* futureValueType= dynamic */ {
41+
core::bool hasThrown = true;
42+
try {
43+
await f{dynamic}.call() /* runtimeCheckType= asy::Future<dynamic> */ ;
44+
hasThrown = false;
45+
}
46+
on core::Object catch(final core::Object e) {
47+
}
48+
if(!hasThrown) {
49+
throw "Expected the function to throw.";
50+
}
51+
}
52+
53+
54+
Extra constant evaluation status:
55+
Evaluated: AsExpression @ org-dartlang-testcase:///issue53052.dart:8:18 -> StringConstant("Hello!")
56+
Evaluated: AsExpression @ org-dartlang-testcase:///issue53052.dart:12:19 -> StringConstant("Hello!")
57+
Extra constant evaluation: evaluated: 33, effectively constant: 2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import 'dart:async';
2+
3+
FutureOr<Iterable<int>> f() sync* {}
4+
FutureOr<Stream<int>> g() async* {}
5+
main() async {}
6+
expectThrows(f) {}
7+
expectAsyncThrows(f) async {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import 'dart:async';
2+
3+
FutureOr<Iterable<int>> f() sync* {}
4+
FutureOr<Stream<int>> g() async* {}
5+
expectAsyncThrows(f) async {}
6+
expectThrows(f) {}
7+
main() async {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
library;
2+
import self as self;
3+
import "dart:core" as core;
4+
import "dart:async" as asy;
5+
6+
import "dart:async";
7+
8+
static method f() → FutureOr<core::Iterable<core::int>> sync* {
9+
yield("Hello!" as dynamic) as{TypeError,ForDynamic} core::int;
10+
}
11+
static method g() → FutureOr<asy::Stream<core::int>> async* {
12+
yield*("Hello!" as dynamic) as{TypeError,ForDynamic} asy::Stream<core::int>;
13+
}
14+
static method main() → dynamic async /* futureValueType= dynamic */ {
15+
FutureOr<core::Iterable<core::int>>iterable = self::f();
16+
if(iterable is asy::Future<core::Object?>)
17+
return;
18+
self::expectThrows(() → Null {
19+
core::int i = iterable{core::Iterable<core::int>}.{core::Iterable::first}{core::int};
20+
});
21+
FutureOr<asy::Stream<core::int>>stream = self::g();
22+
if(stream is asy::Future<core::Object?>)
23+
return;
24+
await self::expectAsyncThrows(() → asy::Future<Null> async /* futureValueType= Null */ {
25+
core::int i = await stream{asy::Stream<core::int>}.{asy::Stream::first}{asy::Future<core::int>};
26+
}) /* runtimeCheckType= asy::Future<dynamic> */ ;
27+
}
28+
static method expectThrows(dynamic f) → dynamic {
29+
core::bool hasThrown = true;
30+
try {
31+
f{dynamic}.call();
32+
hasThrown = false;
33+
}
34+
on core::Object catch(final core::Object e) {
35+
}
36+
if(!hasThrown) {
37+
throw "Expected the function to throw.";
38+
}
39+
}
40+
static method expectAsyncThrows(dynamic f) → dynamic async /* futureValueType= dynamic */ {
41+
core::bool hasThrown = true;
42+
try {
43+
await f{dynamic}.call() /* runtimeCheckType= asy::Future<dynamic> */ ;
44+
hasThrown = false;
45+
}
46+
on core::Object catch(final core::Object e) {
47+
}
48+
if(!hasThrown) {
49+
throw "Expected the function to throw.";
50+
}
51+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
library;
2+
import self as self;
3+
import "dart:core" as core;
4+
import "dart:async" as asy;
5+
6+
import "dart:async";
7+
8+
static method f() → FutureOr<core::Iterable<core::int>> sync* {
9+
yield("Hello!" as dynamic) as{TypeError,ForDynamic} core::int;
10+
}
11+
static method g() → FutureOr<asy::Stream<core::int>> async* {
12+
yield*("Hello!" as dynamic) as{TypeError,ForDynamic} asy::Stream<core::int>;
13+
}
14+
static method main() → dynamic async /* futureValueType= dynamic */ {
15+
FutureOr<core::Iterable<core::int>>iterable = self::f();
16+
if(iterable is asy::Future<core::Object?>)
17+
return;
18+
self::expectThrows(() → Null {
19+
core::int i = iterable{core::Iterable<core::int>}.{core::Iterable::first}{core::int};
20+
});
21+
FutureOr<asy::Stream<core::int>>stream = self::g();
22+
if(stream is asy::Future<core::Object?>)
23+
return;
24+
await self::expectAsyncThrows(() → asy::Future<Null> async /* futureValueType= Null */ {
25+
core::int i = await stream{asy::Stream<core::int>}.{asy::Stream::first}{asy::Future<core::int>};
26+
}) /* runtimeCheckType= asy::Future<dynamic> */ ;
27+
}
28+
static method expectThrows(dynamic f) → dynamic {
29+
core::bool hasThrown = true;
30+
try {
31+
f{dynamic}.call();
32+
hasThrown = false;
33+
}
34+
on core::Object catch(final core::Object e) {
35+
}
36+
if(!hasThrown) {
37+
throw "Expected the function to throw.";
38+
}
39+
}
40+
static method expectAsyncThrows(dynamic f) → dynamic async /* futureValueType= dynamic */ {
41+
core::bool hasThrown = true;
42+
try {
43+
await f{dynamic}.call() /* runtimeCheckType= asy::Future<dynamic> */ ;
44+
hasThrown = false;
45+
}
46+
on core::Object catch(final core::Object e) {
47+
}
48+
if(!hasThrown) {
49+
throw "Expected the function to throw.";
50+
}
51+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
library;
2+
import self as self;
3+
import "dart:core" as core;
4+
import "dart:async" as asy;
5+
6+
import "dart:async";
7+
8+
static method f() → FutureOr<core::Iterable<core::int>> sync*
9+
;
10+
static method g() → FutureOr<asy::Stream<core::int>> async*
11+
;
12+
static method main() → dynamic async
13+
;
14+
static method expectThrows(dynamic f) → dynamic
15+
;
16+
static method expectAsyncThrows(dynamic f) → dynamic async
17+
;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
library;
2+
import self as self;
3+
import "dart:core" as core;
4+
import "dart:async" as asy;
5+
6+
import "dart:async";
7+
8+
static method f() → FutureOr<core::Iterable<core::int>> sync* {
9+
yield("Hello!" as dynamic) as{TypeError,ForDynamic} core::int;
10+
}
11+
static method g() → FutureOr<asy::Stream<core::int>> async* {
12+
yield*("Hello!" as dynamic) as{TypeError,ForDynamic} asy::Stream<core::int>;
13+
}
14+
static method main() → dynamic async /* futureValueType= dynamic */ {
15+
FutureOr<core::Iterable<core::int>>iterable = self::f();
16+
if(iterable is asy::Future<core::Object?>)
17+
return;
18+
self::expectThrows(() → Null {
19+
core::int i = iterable{core::Iterable<core::int>}.{core::Iterable::first}{core::int};
20+
});
21+
FutureOr<asy::Stream<core::int>>stream = self::g();
22+
if(stream is asy::Future<core::Object?>)
23+
return;
24+
await self::expectAsyncThrows(() → asy::Future<Null> async /* futureValueType= Null */ {
25+
core::int i = await stream{asy::Stream<core::int>}.{asy::Stream::first}{asy::Future<core::int>};
26+
}) /* runtimeCheckType= asy::Future<dynamic> */ ;
27+
}
28+
static method expectThrows(dynamic f) → dynamic {
29+
core::bool hasThrown = true;
30+
try {
31+
f{dynamic}.call();
32+
hasThrown = false;
33+
}
34+
on core::Object catch(final core::Object e) {
35+
}
36+
if(!hasThrown) {
37+
throw "Expected the function to throw.";
38+
}
39+
}
40+
static method expectAsyncThrows(dynamic f) → dynamic async /* futureValueType= dynamic */ {
41+
core::bool hasThrown = true;
42+
try {
43+
await f{dynamic}.call() /* runtimeCheckType= asy::Future<dynamic> */ ;
44+
hasThrown = false;
45+
}
46+
on core::Object catch(final core::Object e) {
47+
}
48+
if(!hasThrown) {
49+
throw "Expected the function to throw.";
50+
}
51+
}
52+
53+
54+
Extra constant evaluation status:
55+
Evaluated: AsExpression @ org-dartlang-testcase:///issue53052.dart:8:18 -> StringConstant("Hello!")
56+
Evaluated: AsExpression @ org-dartlang-testcase:///issue53052.dart:12:19 -> StringConstant("Hello!")
57+
Extra constant evaluation: evaluated: 33, effectively constant: 2

0 commit comments

Comments
 (0)