Skip to content

Commit d3463ce

Browse files
authored
Avoid circularly resolving names when looking up type members using resolveName (#26924)
* Avoid circularly resolving names when looking up type members using resolveName * Add comment
1 parent 614423b commit d3463ce

4 files changed

+37
-1
lines changed

src/compiler/checker.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1312,7 +1312,10 @@ namespace ts {
13121312
case SyntaxKind.ClassDeclaration:
13131313
case SyntaxKind.ClassExpression:
13141314
case SyntaxKind.InterfaceDeclaration:
1315-
if (result = lookup(getMembersOfSymbol(getSymbolOfNode(location as ClassLikeDeclaration | InterfaceDeclaration)), name, meaning & SymbolFlags.Type)) {
1315+
// The below is used to lookup type parameters within a class or interface, as they are added to the class/interface locals
1316+
// These can never be latebound, so the symbol's raw members are sufficient. `getMembersOfNode` cannot be used, as it would
1317+
// trigger resolving late-bound names, which we may already be in the process of doing while we're here!
1318+
if (result = lookup(getSymbolOfNode(location as ClassLikeDeclaration | InterfaceDeclaration).members || emptySymbols, name, meaning & SymbolFlags.Type)) {
13161319
if (!isTypeParameterSymbolDeclaredInContainer(result, location)) {
13171320
// ignore type parameters not declared in this container
13181321
result = undefined;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
=== tests/cases/compiler/index.d.ts ===
2+
export class C extends Object {
3+
>C : Symbol(C, Decl(index.d.ts, 0, 0))
4+
>Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
5+
6+
static readonly p: unique symbol;
7+
>p : Symbol(C.p, Decl(index.d.ts, 0, 31))
8+
9+
[C.p](): void;
10+
>[C.p] : Symbol(C[C.p], Decl(index.d.ts, 1, 37))
11+
>C.p : Symbol(C.p, Decl(index.d.ts, 0, 31))
12+
>C : Symbol(C, Decl(index.d.ts, 0, 0))
13+
>p : Symbol(C.p, Decl(index.d.ts, 0, 31))
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
=== tests/cases/compiler/index.d.ts ===
2+
export class C extends Object {
3+
>C : C
4+
>Object : Object
5+
6+
static readonly p: unique symbol;
7+
>p : unique symbol
8+
9+
[C.p](): void;
10+
>[C.p] : () => void
11+
>C.p : unique symbol
12+
>C : typeof C
13+
>p : unique symbol
14+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// @filename: index.d.ts
2+
export class C extends Object {
3+
static readonly p: unique symbol;
4+
[C.p](): void;
5+
}

0 commit comments

Comments
 (0)