Skip to content

Commit ac90de3

Browse files
committed
Add tests
1 parent b601045 commit ac90de3

9 files changed

+118
-4
lines changed

Diff for: src/compiler/checker.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -4012,7 +4012,7 @@ namespace ts {
40124012
}
40134013
if (type.flags & TypeFlags.TypeParameter || objectFlags & ObjectFlags.ClassOrInterface) {
40144014
if (type.flags & TypeFlags.TypeParameter && contains(context.inferTypeParameters, type)) {
4015-
context.approximateLength += (symbolName(type.symbol).length + 6);
4015+
context.approximateLength += 6 + (type.symbol ? symbolName(type.symbol).length : 1);
40164016
return createInferTypeNode(typeParameterToDeclarationWithConstraint(type as TypeParameter, context, /*constraintNode*/ undefined));
40174017
}
40184018
if (context.flags & NodeBuilderFlags.GenerateNamesForShadowedTypeParams &&
@@ -4947,7 +4947,7 @@ namespace ts {
49474947
return cached;
49484948
}
49494949
}
4950-
let result = symbolToName(type.symbol, context, SymbolFlags.Type, /*expectsIdentifier*/ true);
4950+
let result = type.symbol ? symbolToName(type.symbol, context, SymbolFlags.Type, /*expectsIdentifier*/ true) : createIdentifier("?");
49514951
if (!(result.kind & SyntaxKind.Identifier)) {
49524952
return createIdentifier("(Missing type parameter)");
49534953
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
=== tests/cases/conformance/async/es2017/asyncArrowFunction/asyncArrowFunctionCapturesThis_es2017.ts ===
2+
class C {
3+
>C : C
4+
5+
method() {
6+
>method : () => void
7+
8+
var fn = async () => await this;
9+
>fn : () => Promise<this extends undefined ? this : this extends PromiseLike<infer ?> ? ? : this>
10+
>async () => await this : () => Promise<this extends undefined ? this : this extends PromiseLike<infer ?> ? ? : this>
11+
>await this : this extends undefined ? this : this extends PromiseLike<infer ?> ? ? : this
12+
>this : this
13+
}
14+
}
15+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
=== tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunctionCapturesThis_es5.ts ===
2+
class C {
3+
>C : C
4+
5+
method() {
6+
>method : () => void
7+
8+
var fn = async () => await this;
9+
>fn : () => Promise<this extends undefined ? this : this extends PromiseLike<infer ?> ? ? : this>
10+
>async () => await this : () => Promise<this extends undefined ? this : this extends PromiseLike<infer ?> ? ? : this>
11+
>await this : this extends undefined ? this : this extends PromiseLike<infer ?> ? ? : this
12+
>this : this
13+
}
14+
}
15+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
=== tests/cases/conformance/async/es6/asyncArrowFunction/asyncArrowFunctionCapturesThis_es6.ts ===
2+
class C {
3+
>C : C
4+
5+
method() {
6+
>method : () => void
7+
8+
var fn = async () => await this;
9+
>fn : () => Promise<this extends undefined ? this : this extends PromiseLike<infer ?> ? ? : this>
10+
>async () => await this : () => Promise<this extends undefined ? this : this extends PromiseLike<infer ?> ? ? : this>
11+
>await this : this extends undefined ? this : this extends PromiseLike<infer ?> ? ? : this
12+
>this : this
13+
}
14+
}
15+

Diff for: tests/baselines/reference/asyncFunctionReturnType.js

+16-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,15 @@ async function fGenericIndexedTypeForPromiseOfKProp<TObj extends Obj, K extends
7373

7474
async function fGenericIndexedTypeForExplicitPromiseOfKProp<TObj extends Obj, K extends keyof TObj>(obj: TObj, key: K): Promise<TObj[K]> {
7575
return Promise.resolve<TObj[K]>(obj[key]);
76-
}
76+
}
77+
78+
// #27711
79+
80+
async function fGeneric<T>(x: T) {
81+
return x;
82+
}
83+
const expected: Promise<string> = fGeneric(undefined as Promise<string>);
84+
7785

7886
//// [asyncFunctionReturnType.js]
7987
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
@@ -172,3 +180,10 @@ function fGenericIndexedTypeForExplicitPromiseOfKProp(obj, key) {
172180
return Promise.resolve(obj[key]);
173181
});
174182
}
183+
// #27711
184+
function fGeneric(x) {
185+
return __awaiter(this, void 0, void 0, function* () {
186+
return x;
187+
});
188+
}
189+
const expected = fGeneric(undefined);

Diff for: tests/baselines/reference/asyncFunctionReturnType.symbols

+19
Original file line numberDiff line numberDiff line change
@@ -285,3 +285,22 @@ async function fGenericIndexedTypeForExplicitPromiseOfKProp<TObj extends Obj, K
285285
>obj : Symbol(obj, Decl(asyncFunctionReturnType.ts, 72, 100))
286286
>key : Symbol(key, Decl(asyncFunctionReturnType.ts, 72, 110))
287287
}
288+
289+
// #27711
290+
291+
async function fGeneric<T>(x: T) {
292+
>fGeneric : Symbol(fGeneric, Decl(asyncFunctionReturnType.ts, 74, 1))
293+
>T : Symbol(T, Decl(asyncFunctionReturnType.ts, 78, 24))
294+
>x : Symbol(x, Decl(asyncFunctionReturnType.ts, 78, 27))
295+
>T : Symbol(T, Decl(asyncFunctionReturnType.ts, 78, 24))
296+
297+
return x;
298+
>x : Symbol(x, Decl(asyncFunctionReturnType.ts, 78, 27))
299+
}
300+
const expected: Promise<string> = fGeneric(undefined as Promise<string>);
301+
>expected : Symbol(expected, Decl(asyncFunctionReturnType.ts, 81, 5))
302+
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))
303+
>fGeneric : Symbol(fGeneric, Decl(asyncFunctionReturnType.ts, 74, 1))
304+
>undefined : Symbol(undefined)
305+
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))
306+

Diff for: tests/baselines/reference/asyncFunctionReturnType.types

+17
Original file line numberDiff line numberDiff line change
@@ -220,3 +220,20 @@ async function fGenericIndexedTypeForExplicitPromiseOfKProp<TObj extends Obj, K
220220
>obj : TObj
221221
>key : K
222222
}
223+
224+
// #27711
225+
226+
async function fGeneric<T>(x: T) {
227+
>fGeneric : <T>(x: T) => Promise<T extends undefined ? T : T extends PromiseLike<infer ?> ? ? : T>
228+
>x : T
229+
230+
return x;
231+
>x : T
232+
}
233+
const expected: Promise<string> = fGeneric(undefined as Promise<string>);
234+
>expected : Promise<string>
235+
>fGeneric(undefined as Promise<string>) : Promise<string>
236+
>fGeneric : <T>(x: T) => Promise<T extends undefined ? T : T extends PromiseLike<infer ?> ? ? : T>
237+
>undefined as Promise<string> : Promise<string>
238+
>undefined : undefined
239+

Diff for: tests/baselines/reference/forAwaitForUnion.types

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
=== tests/cases/compiler/forAwaitForUnion.ts ===
2+
async function f<T>(source: Iterable<T> | AsyncIterable<T>) {
3+
>f : <T>(source: Iterable<T> | AsyncIterable<T>) => Promise<void>
4+
>source : Iterable<T> | AsyncIterable<T>
5+
6+
for await (const x of source) {
7+
>x : T | (T extends undefined ? T : T extends PromiseLike<infer ?> ? ? : T)
8+
>source : Iterable<T> | AsyncIterable<T>
9+
}
10+
}
11+

Diff for: tests/cases/compiler/asyncFunctionReturnType.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,11 @@ async function fGenericIndexedTypeForPromiseOfKProp<TObj extends Obj, K extends
7373

7474
async function fGenericIndexedTypeForExplicitPromiseOfKProp<TObj extends Obj, K extends keyof TObj>(obj: TObj, key: K): Promise<TObj[K]> {
7575
return Promise.resolve<TObj[K]>(obj[key]);
76-
}
76+
}
77+
78+
// #27711
79+
80+
async function fGeneric<T>(x: T) {
81+
return x;
82+
}
83+
const expected: Promise<string> = fGeneric(undefined as Promise<string>);

0 commit comments

Comments
 (0)