Skip to content

Commit 5d2e57e

Browse files
Fix for crash when using ca call expression on private identifier coming from an any typed variable. (GH #42860)
1 parent 05ee94f commit 5d2e57e

File tree

6 files changed

+24
-1
lines changed

6 files changed

+24
-1
lines changed

src/compiler/checker.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21978,7 +21978,17 @@ namespace ts {
2197821978
const type = getTypeOfDottedName((<PropertyAccessExpression>node).expression, diagnostic);
2197921979
if (type) {
2198021980
const name = (<PropertyAccessExpression>node).name;
21981-
const prop = getPropertyOfType(type, isPrivateIdentifier(name) ? getSymbolNameForPrivateIdentifier(type.symbol, name.escapedText) : name.escapedText);
21981+
let prop: Symbol | undefined;
21982+
if (isPrivateIdentifier(name)) {
21983+
const isAnyLike = isTypeAny(type) || type === silentNeverType;
21984+
if (isAnyLike) {
21985+
return undefined;
21986+
}
21987+
prop = getPropertyOfType(type, getSymbolNameForPrivateIdentifier(type.symbol, name.escapedText));
21988+
}
21989+
else {
21990+
prop = getPropertyOfType(type, name.escapedText);
21991+
}
2198221992
return prop && getExplicitTypeOfSymbol(prop, diagnostic);
2198321993
}
2198421994
return undefined;

tests/baselines/reference/privateNameAndAny.errors.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ tests/cases/conformance/classes/members/privateNames/privateNameAndAny.ts(5,15):
99
thing.#bar; // Error
1010
~~~~
1111
!!! error TS2339: Property '#bar' does not exist on type 'any'.
12+
thing.#foo();
1213
}
1314
};
1415

tests/baselines/reference/privateNameAndAny.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ class A {
44
method(thing: any) {
55
thing.#foo; // OK
66
thing.#bar; // Error
7+
thing.#foo();
78
}
89
};
910

@@ -24,6 +25,8 @@ class A {
2425
method(thing) {
2526
__classPrivateFieldGet(thing, _foo); // OK
2627
thing.; // Error
28+
__classPrivateFieldGet(thing, _foo).call(// Error
29+
thing);
2730
}
2831
}
2932
_foo = new WeakMap();

tests/baselines/reference/privateNameAndAny.symbols

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ class A {
1414

1515
thing.#bar; // Error
1616
>thing : Symbol(thing, Decl(privateNameAndAny.ts, 2, 11))
17+
18+
thing.#foo();
19+
>thing : Symbol(thing, Decl(privateNameAndAny.ts, 2, 11))
1720
}
1821
};
1922

tests/baselines/reference/privateNameAndAny.types

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ class A {
1616

1717
thing.#bar; // Error
1818
>thing.#bar : any
19+
>thing : any
20+
21+
thing.#foo();
22+
>thing.#foo() : any
23+
>thing.#foo : any
1924
>thing : any
2025
}
2126
};

tests/cases/conformance/classes/members/privateNames/privateNameAndAny.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ class A {
66
method(thing: any) {
77
thing.#foo; // OK
88
thing.#bar; // Error
9+
thing.#foo();
910
}
1011
};

0 commit comments

Comments
 (0)