Skip to content

Commit

Permalink
Fix for crash when using ca call expression on private identifier com…
Browse files Browse the repository at this point in the history
…ing from an any typed variable. (GH #42860)
  • Loading branch information
dragomirtitian committed Feb 18, 2021
1 parent 05ee94f commit 5d2e57e
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/compiler/checker.ts
Expand Up @@ -21978,7 +21978,17 @@ namespace ts {
const type = getTypeOfDottedName((<PropertyAccessExpression>node).expression, diagnostic);
if (type) {
const name = (<PropertyAccessExpression>node).name;
const prop = getPropertyOfType(type, isPrivateIdentifier(name) ? getSymbolNameForPrivateIdentifier(type.symbol, name.escapedText) : name.escapedText);
let prop: Symbol | undefined;
if (isPrivateIdentifier(name)) {
const isAnyLike = isTypeAny(type) || type === silentNeverType;
if (isAnyLike) {
return undefined;
}
prop = getPropertyOfType(type, getSymbolNameForPrivateIdentifier(type.symbol, name.escapedText));
}
else {
prop = getPropertyOfType(type, name.escapedText);
}
return prop && getExplicitTypeOfSymbol(prop, diagnostic);
}
return undefined;
Expand Down
1 change: 1 addition & 0 deletions tests/baselines/reference/privateNameAndAny.errors.txt
Expand Up @@ -9,6 +9,7 @@ tests/cases/conformance/classes/members/privateNames/privateNameAndAny.ts(5,15):
thing.#bar; // Error
~~~~
!!! error TS2339: Property '#bar' does not exist on type 'any'.
thing.#foo();
}
};

3 changes: 3 additions & 0 deletions tests/baselines/reference/privateNameAndAny.js
Expand Up @@ -4,6 +4,7 @@ class A {
method(thing: any) {
thing.#foo; // OK
thing.#bar; // Error
thing.#foo();
}
};

Expand All @@ -24,6 +25,8 @@ class A {
method(thing) {
__classPrivateFieldGet(thing, _foo); // OK
thing.; // Error
__classPrivateFieldGet(thing, _foo).call(// Error
thing);
}
}
_foo = new WeakMap();
Expand Down
3 changes: 3 additions & 0 deletions tests/baselines/reference/privateNameAndAny.symbols
Expand Up @@ -14,6 +14,9 @@ class A {

thing.#bar; // Error
>thing : Symbol(thing, Decl(privateNameAndAny.ts, 2, 11))

thing.#foo();
>thing : Symbol(thing, Decl(privateNameAndAny.ts, 2, 11))
}
};

5 changes: 5 additions & 0 deletions tests/baselines/reference/privateNameAndAny.types
Expand Up @@ -16,6 +16,11 @@ class A {

thing.#bar; // Error
>thing.#bar : any
>thing : any

thing.#foo();
>thing.#foo() : any
>thing.#foo : any
>thing : any
}
};
Expand Down
Expand Up @@ -6,5 +6,6 @@ class A {
method(thing: any) {
thing.#foo; // OK
thing.#bar; // Error
thing.#foo();
}
};

0 comments on commit 5d2e57e

Please sign in to comment.