Skip to content

Commit 17e0d29

Browse files
committed
fix(47561): use parameter name from enclosing declaration
1 parent a9efe2b commit 17e0d29

File tree

5 files changed

+181
-1
lines changed

5 files changed

+181
-1
lines changed

src/compiler/checker.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6393,7 +6393,8 @@ namespace ts {
63936393
includePrivateSymbol?.(sym);
63946394
}
63956395
if (isIdentifier(node)) {
6396-
const name = sym.flags & SymbolFlags.TypeParameter ? typeParameterToName(getDeclaredTypeOfSymbol(sym), context) : factory.cloneNode(node);
6396+
const type = getDeclaredTypeOfSymbol(sym);
6397+
const name = sym.flags & SymbolFlags.TypeParameter && !isTypeSymbolAccessible(type.symbol, context.enclosingDeclaration) ? typeParameterToName(type, context) : factory.cloneNode(node);
63976398
name.symbol = sym; // for quickinfo, which uses identifier symbol information
63986399
return { introducesError, node: setEmitFlags(setOriginalNode(name, node), EmitFlags.NoAsciiEscaping) };
63996400
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
//// [typeParametersAvailableInNestedScope3.ts]
2+
function foo<T>(v: T) {
3+
function a<T>(a: T) {
4+
return a;
5+
}
6+
function b(): T {
7+
return v;
8+
}
9+
10+
function c<T>(v: T) {
11+
function a<T>(a: T) {
12+
return a;
13+
}
14+
function b(): T {
15+
return v;
16+
}
17+
18+
return { a, b };
19+
}
20+
21+
return { a, b, c };
22+
}
23+
24+
25+
26+
//// [typeParametersAvailableInNestedScope3.js]
27+
function foo(v) {
28+
function a(a) {
29+
return a;
30+
}
31+
function b() {
32+
return v;
33+
}
34+
function c(v) {
35+
function a(a) {
36+
return a;
37+
}
38+
function b() {
39+
return v;
40+
}
41+
return { a: a, b: b };
42+
}
43+
return { a: a, b: b, c: c };
44+
}
45+
46+
47+
//// [typeParametersAvailableInNestedScope3.d.ts]
48+
declare function foo<T>(v: T): {
49+
a: <T_1>(a: T_1) => T_1;
50+
b: () => T;
51+
c: <T_2>(v: T_2) => {
52+
a: <T_3>(a: T_3) => T_3;
53+
b: () => T_2;
54+
};
55+
};
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
=== tests/cases/conformance/types/typeParameters/typeParameterLists/typeParametersAvailableInNestedScope3.ts ===
2+
function foo<T>(v: T) {
3+
>foo : Symbol(foo, Decl(typeParametersAvailableInNestedScope3.ts, 0, 0))
4+
>T : Symbol(T, Decl(typeParametersAvailableInNestedScope3.ts, 0, 13))
5+
>v : Symbol(v, Decl(typeParametersAvailableInNestedScope3.ts, 0, 16))
6+
>T : Symbol(T, Decl(typeParametersAvailableInNestedScope3.ts, 0, 13))
7+
8+
function a<T>(a: T) {
9+
>a : Symbol(a, Decl(typeParametersAvailableInNestedScope3.ts, 0, 23))
10+
>T : Symbol(T, Decl(typeParametersAvailableInNestedScope3.ts, 1, 15))
11+
>a : Symbol(a, Decl(typeParametersAvailableInNestedScope3.ts, 1, 18))
12+
>T : Symbol(T, Decl(typeParametersAvailableInNestedScope3.ts, 1, 15))
13+
14+
return a;
15+
>a : Symbol(a, Decl(typeParametersAvailableInNestedScope3.ts, 1, 18))
16+
}
17+
function b(): T {
18+
>b : Symbol(b, Decl(typeParametersAvailableInNestedScope3.ts, 3, 5))
19+
>T : Symbol(T, Decl(typeParametersAvailableInNestedScope3.ts, 0, 13))
20+
21+
return v;
22+
>v : Symbol(v, Decl(typeParametersAvailableInNestedScope3.ts, 0, 16))
23+
}
24+
25+
function c<T>(v: T) {
26+
>c : Symbol(c, Decl(typeParametersAvailableInNestedScope3.ts, 6, 5))
27+
>T : Symbol(T, Decl(typeParametersAvailableInNestedScope3.ts, 8, 15))
28+
>v : Symbol(v, Decl(typeParametersAvailableInNestedScope3.ts, 8, 18))
29+
>T : Symbol(T, Decl(typeParametersAvailableInNestedScope3.ts, 8, 15))
30+
31+
function a<T>(a: T) {
32+
>a : Symbol(a, Decl(typeParametersAvailableInNestedScope3.ts, 8, 25))
33+
>T : Symbol(T, Decl(typeParametersAvailableInNestedScope3.ts, 9, 19))
34+
>a : Symbol(a, Decl(typeParametersAvailableInNestedScope3.ts, 9, 22))
35+
>T : Symbol(T, Decl(typeParametersAvailableInNestedScope3.ts, 9, 19))
36+
37+
return a;
38+
>a : Symbol(a, Decl(typeParametersAvailableInNestedScope3.ts, 9, 22))
39+
}
40+
function b(): T {
41+
>b : Symbol(b, Decl(typeParametersAvailableInNestedScope3.ts, 11, 9))
42+
>T : Symbol(T, Decl(typeParametersAvailableInNestedScope3.ts, 8, 15))
43+
44+
return v;
45+
>v : Symbol(v, Decl(typeParametersAvailableInNestedScope3.ts, 8, 18))
46+
}
47+
48+
return { a, b };
49+
>a : Symbol(a, Decl(typeParametersAvailableInNestedScope3.ts, 16, 16))
50+
>b : Symbol(b, Decl(typeParametersAvailableInNestedScope3.ts, 16, 19))
51+
}
52+
53+
return { a, b, c };
54+
>a : Symbol(a, Decl(typeParametersAvailableInNestedScope3.ts, 19, 12))
55+
>b : Symbol(b, Decl(typeParametersAvailableInNestedScope3.ts, 19, 15))
56+
>c : Symbol(c, Decl(typeParametersAvailableInNestedScope3.ts, 19, 18))
57+
}
58+
59+
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
=== tests/cases/conformance/types/typeParameters/typeParameterLists/typeParametersAvailableInNestedScope3.ts ===
2+
function foo<T>(v: T) {
3+
>foo : <T>(v: T) => { a: <T>(a: T) => T; b: () => T; c: <T>(v: T) => { a: <T>(a: T) => T; b: () => T; }; }
4+
>v : T
5+
6+
function a<T>(a: T) {
7+
>a : <T>(a: T) => T
8+
>a : T
9+
10+
return a;
11+
>a : T
12+
}
13+
function b(): T {
14+
>b : () => T
15+
16+
return v;
17+
>v : T
18+
}
19+
20+
function c<T>(v: T) {
21+
>c : <T>(v: T) => { a: <T>(a: T) => T; b: () => T; }
22+
>v : T
23+
24+
function a<T>(a: T) {
25+
>a : <T>(a: T) => T
26+
>a : T
27+
28+
return a;
29+
>a : T
30+
}
31+
function b(): T {
32+
>b : () => T
33+
34+
return v;
35+
>v : T
36+
}
37+
38+
return { a, b };
39+
>{ a, b } : { a: <T>(a: T) => T; b: () => T; }
40+
>a : <T>(a: T) => T
41+
>b : () => T
42+
}
43+
44+
return { a, b, c };
45+
>{ a, b, c } : { a: <T>(a: T) => T; b: () => T; c: <T>(v: T) => { a: <T>(a: T) => T; b: () => T; }; }
46+
>a : <T>(a: T) => T
47+
>b : () => T
48+
>c : <T>(v: T) => { a: <T>(a: T) => T; b: () => T; }
49+
}
50+
51+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// @declaration: true
2+
3+
function foo<T>(v: T) {
4+
function a<T>(a: T) { return a; }
5+
function b(): T { return v; }
6+
7+
function c<T>(v: T) {
8+
function a<T>(a: T) { return a; }
9+
function b(): T { return v; }
10+
return { a, b };
11+
}
12+
13+
return { a, b, c };
14+
}

0 commit comments

Comments
 (0)