Skip to content

Commit 46587c8

Browse files
authored
Merge pull request #14235 from Microsoft/master-fix14043
[Master] fix 14043 collect return type from return statement in generator function
2 parents f5d566e + 71e52de commit 46587c8

23 files changed

+532
-26
lines changed

src/compiler/checker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15146,8 +15146,8 @@ namespace ts {
1514615146
else {
1514715147
let types: Type[];
1514815148
if (functionFlags & FunctionFlags.Generator) { // Generator or AsyncGenerator function
15149-
types = checkAndAggregateYieldOperandTypes(func, checkMode);
15150-
if (types.length === 0) {
15149+
types = concatenate(checkAndAggregateYieldOperandTypes(func, checkMode), checkAndAggregateReturnExpressionTypes(func, checkMode));
15150+
if (!types || types.length === 0) {
1515115151
const iterableIteratorAny = functionFlags & FunctionFlags.Async
1515215152
? createAsyncIterableIteratorType(anyType) // AsyncGenerator function
1515315153
: createIterableIteratorType(anyType); // Generator function

tests/baselines/reference/emitter.asyncGenerators.classMethods.es2015.types

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class C7 {
8080
>C7 : C7
8181

8282
async * f() {
83-
>f : () => AsyncIterableIterator<any>
83+
>f : () => AsyncIterableIterator<1>
8484

8585
return 1;
8686
>1 : 1

tests/baselines/reference/emitter.asyncGenerators.classMethods.es5.types

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class C7 {
8080
>C7 : C7
8181

8282
async * f() {
83-
>f : () => AsyncIterableIterator<any>
83+
>f : () => AsyncIterableIterator<1>
8484

8585
return 1;
8686
>1 : 1

tests/baselines/reference/emitter.asyncGenerators.classMethods.esnext.types

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class C7 {
8080
>C7 : C7
8181

8282
async * f() {
83-
>f : () => AsyncIterableIterator<any>
83+
>f : () => AsyncIterableIterator<1>
8484

8585
return 1;
8686
>1 : 1

tests/baselines/reference/emitter.asyncGenerators.functionDeclarations.es2015.types

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ async function * f6() {
5353
}
5454
=== tests/cases/conformance/emitter/es2015/asyncGenerators/F7.ts ===
5555
async function * f7() {
56-
>f7 : () => AsyncIterableIterator<any>
56+
>f7 : () => AsyncIterableIterator<1>
5757

5858
return 1;
5959
>1 : 1

tests/baselines/reference/emitter.asyncGenerators.functionDeclarations.es5.types

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ async function * f6() {
5353
}
5454
=== tests/cases/conformance/emitter/es5/asyncGenerators/F7.ts ===
5555
async function * f7() {
56-
>f7 : () => AsyncIterableIterator<any>
56+
>f7 : () => AsyncIterableIterator<1>
5757

5858
return 1;
5959
>1 : 1

tests/baselines/reference/emitter.asyncGenerators.functionDeclarations.esnext.types

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ async function * f6() {
5353
}
5454
=== tests/cases/conformance/emitter/esnext/asyncGenerators/F7.ts ===
5555
async function * f7() {
56-
>f7 : () => AsyncIterableIterator<any>
56+
>f7 : () => AsyncIterableIterator<1>
5757

5858
return 1;
5959
>1 : 1

tests/baselines/reference/emitter.asyncGenerators.functionExpressions.es2015.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ const f6 = async function * () {
5959
}
6060
=== tests/cases/conformance/emitter/es2015/asyncGenerators/F7.ts ===
6161
const f7 = async function * () {
62-
>f7 : () => AsyncIterableIterator<any>
63-
>async function * () { return 1;} : () => AsyncIterableIterator<any>
62+
>f7 : () => AsyncIterableIterator<1>
63+
>async function * () { return 1;} : () => AsyncIterableIterator<1>
6464

6565
return 1;
6666
>1 : 1

tests/baselines/reference/emitter.asyncGenerators.functionExpressions.es5.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ const f6 = async function * () {
5959
}
6060
=== tests/cases/conformance/emitter/es5/asyncGenerators/F7.ts ===
6161
const f7 = async function * () {
62-
>f7 : () => AsyncIterableIterator<any>
63-
>async function * () { return 1;} : () => AsyncIterableIterator<any>
62+
>f7 : () => AsyncIterableIterator<1>
63+
>async function * () { return 1;} : () => AsyncIterableIterator<1>
6464

6565
return 1;
6666
>1 : 1

tests/baselines/reference/emitter.asyncGenerators.functionExpressions.esnext.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ const f6 = async function * () {
5959
}
6060
=== tests/cases/conformance/emitter/esnext/asyncGenerators/F7.ts ===
6161
const f7 = async function * () {
62-
>f7 : () => AsyncIterableIterator<any>
63-
>async function * () { return 1;} : () => AsyncIterableIterator<any>
62+
>f7 : () => AsyncIterableIterator<1>
63+
>async function * () { return 1;} : () => AsyncIterableIterator<1>
6464

6565
return 1;
6666
>1 : 1

0 commit comments

Comments
 (0)