Fix crash in abstract property checking#62923
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes a crash (issue #62920) that occurred when TypeScript tried to report an error about accessing an abstract property in the constructor of an unnamed class expression. The crash happened because the code attempted to access the name property of an unnamed class declaration, which is undefined for class expressions without explicit names.
Key Changes
- Modified the abstract property accessibility check to avoid dereferencing potentially undefined values
- Changed error message generation to use
symbolToString()instead of accessing the class declaration's name property directly - Added a test case demonstrating the crash scenario with appropriate baselines
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
src/compiler/checker.ts |
Fixed crash by checking parent symbol validity and using symbolToString() instead of accessing declaration name |
tests/cases/compiler/errorInUnnamedClassExpression.ts |
Added test case with unnamed class expression containing abstract property accessed in constructor |
tests/baselines/reference/errorInUnnamedClassExpression.types |
Baseline for type information |
tests/baselines/reference/errorInUnnamedClassExpression.symbols |
Baseline for symbol information |
tests/baselines/reference/errorInUnnamedClassExpression.errors.txt |
Baseline showing correct error messages (TS2715, TS1253, TS7008) |
| const declaringClassDeclaration = getClassLikeDeclarationOfSymbol(getParentOfSymbol(prop)!); | ||
| if (declaringClassDeclaration && isNodeUsedDuringClassInitialization(location)) { | ||
| const parentSymbol = getParentOfSymbol(prop); | ||
| if (parentSymbol && parentSymbol.flags & SymbolFlags.Class && isNodeUsedDuringClassInitialization(location)) { |
There was a problem hiding this comment.
Missing spaces around the bitwise AND operator. The pattern should be parentSymbol.flags & SymbolFlags.Class with spaces on both sides of the & operator to match the codebase style.
|
This was ported to typescript-go in microsoft/typescript-go#2423. |
Fixes #62920.