Skip to content

Commit f9a7cbf

Browse files
authored
Fix crash in getAwaitedType (#54107)
1 parent e18c935 commit f9a7cbf

6 files changed

+128
-1
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2036,7 +2036,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
20362036
getGlobalIterableType: getGlobalAsyncIterableType,
20372037
getGlobalIterableIteratorType: getGlobalAsyncIterableIteratorType,
20382038
getGlobalGeneratorType: getGlobalAsyncGeneratorType,
2039-
resolveIterationType: getAwaitedType,
2039+
resolveIterationType: (type, errorNode) => getAwaitedType(type, errorNode, Diagnostics.Type_of_await_operand_must_either_be_a_valid_promise_or_must_not_contain_a_callable_then_member),
20402040
mustHaveANextMethodDiagnostic: Diagnostics.An_async_iterator_must_have_a_next_method,
20412041
mustBeAMethodDiagnostic: Diagnostics.The_0_property_of_an_async_iterator_must_be_a_method,
20422042
mustHaveAValueDiagnostic: Diagnostics.The_type_returned_by_the_0_method_of_an_async_iterator_must_be_a_promise_for_a_type_with_a_value_property,
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
tests/cases/compiler/crashInYieldStarInAsyncFunction.ts(13,12): error TS1320: Type of 'await' operand must either be a valid promise or must not contain a callable 'then' member.
2+
3+
4+
==== tests/cases/compiler/crashInYieldStarInAsyncFunction.ts (1 errors) ====
5+
// https://github.com/microsoft/TypeScript/issues/53145
6+
var obj = {
7+
[Symbol.asyncIterator]() {
8+
return {
9+
next() {
10+
return { then() { } };
11+
}
12+
};
13+
}
14+
};
15+
16+
async function* g() {
17+
yield* obj;
18+
~~~
19+
!!! error TS1320: Type of 'await' operand must either be a valid promise or must not contain a callable 'then' member.
20+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//// [crashInYieldStarInAsyncFunction.ts]
2+
// https://github.com/microsoft/TypeScript/issues/53145
3+
var obj = {
4+
[Symbol.asyncIterator]() {
5+
return {
6+
next() {
7+
return { then() { } };
8+
}
9+
};
10+
}
11+
};
12+
13+
async function* g() {
14+
yield* obj;
15+
}
16+
17+
//// [crashInYieldStarInAsyncFunction.js]
18+
// https://github.com/microsoft/TypeScript/issues/53145
19+
var obj = {
20+
[Symbol.asyncIterator]() {
21+
return {
22+
next() {
23+
return { then() { } };
24+
}
25+
};
26+
}
27+
};
28+
async function* g() {
29+
yield* obj;
30+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
=== tests/cases/compiler/crashInYieldStarInAsyncFunction.ts ===
2+
// https://github.com/microsoft/TypeScript/issues/53145
3+
var obj = {
4+
>obj : Symbol(obj, Decl(crashInYieldStarInAsyncFunction.ts, 1, 3))
5+
6+
[Symbol.asyncIterator]() {
7+
>[Symbol.asyncIterator] : Symbol([Symbol.asyncIterator], Decl(crashInYieldStarInAsyncFunction.ts, 1, 11))
8+
>Symbol.asyncIterator : Symbol(SymbolConstructor.asyncIterator, Decl(lib.es2018.asynciterable.d.ts, --, --))
9+
>Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2019.symbol.d.ts, --, --))
10+
>asyncIterator : Symbol(SymbolConstructor.asyncIterator, Decl(lib.es2018.asynciterable.d.ts, --, --))
11+
12+
return {
13+
next() {
14+
>next : Symbol(next, Decl(crashInYieldStarInAsyncFunction.ts, 3, 16))
15+
16+
return { then() { } };
17+
>then : Symbol(then, Decl(crashInYieldStarInAsyncFunction.ts, 5, 24))
18+
}
19+
};
20+
}
21+
};
22+
23+
async function* g() {
24+
>g : Symbol(g, Decl(crashInYieldStarInAsyncFunction.ts, 9, 2))
25+
26+
yield* obj;
27+
>obj : Symbol(obj, Decl(crashInYieldStarInAsyncFunction.ts, 1, 3))
28+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
=== tests/cases/compiler/crashInYieldStarInAsyncFunction.ts ===
2+
// https://github.com/microsoft/TypeScript/issues/53145
3+
var obj = {
4+
>obj : { [Symbol.asyncIterator](): { next(): { then(): void; }; }; }
5+
>{ [Symbol.asyncIterator]() { return { next() { return { then() { } }; } }; }} : { [Symbol.asyncIterator](): { next(): { then(): void; }; }; }
6+
7+
[Symbol.asyncIterator]() {
8+
>[Symbol.asyncIterator] : () => { next(): { then(): void; }; }
9+
>Symbol.asyncIterator : unique symbol
10+
>Symbol : SymbolConstructor
11+
>asyncIterator : unique symbol
12+
13+
return {
14+
>{ next() { return { then() { } }; } } : { next(): { then(): void; }; }
15+
16+
next() {
17+
>next : () => { then(): void; }
18+
19+
return { then() { } };
20+
>{ then() { } } : { then(): void; }
21+
>then : () => void
22+
}
23+
};
24+
}
25+
};
26+
27+
async function* g() {
28+
>g : () => AsyncGenerator<any, void, unknown>
29+
30+
yield* obj;
31+
>yield* obj : any
32+
>obj : { [Symbol.asyncIterator](): { next(): { then(): void; }; }; }
33+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// @target: esnext
2+
3+
// https://github.com/microsoft/TypeScript/issues/53145
4+
var obj = {
5+
[Symbol.asyncIterator]() {
6+
return {
7+
next() {
8+
return { then() { } };
9+
}
10+
};
11+
}
12+
};
13+
14+
async function* g() {
15+
yield* obj;
16+
}

0 commit comments

Comments
 (0)