Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 23, 2025

Ports TypeScript PR #62923 which fixes a crash when checking abstract properties in unnamed class expressions. The compiler previously crashed with Cannot read properties of undefined (reading 'kind') when encountering abstract properties in class expressions without names.

Changes

  • internal/checker/checker.go: Modified checkPropertyAccessibilityAtLocation to check parent symbol flags directly instead of calling GetClassLikeDeclarationOfSymbol, which returns nil for unnamed class expressions. Now uses symbolToString(parentSymbol) for error messages, handling both named and unnamed classes.

  • testdata/tests/cases/compiler/errorInUnnamedClassExpression.ts: Added test case covering the crash scenario.

Example

Previously crashed:

let Foo = class {
    constructor() {
        this.bar++;  // Compiler crashes here
    }
    abstract bar;
};

Now produces proper error:

error TS2715: Abstract property 'bar' in class 'Foo' cannot be accessed in the constructor.
Original prompt

Port PR 62923


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

This ports TypeScript PR #62923 which fixes issue #62920 - a crash when
using abstract properties in class expressions.

The fix changes how we check for abstract properties in constructors:
- Instead of getting the class declaration and accessing its name (which
  crashes for unnamed class expressions), we now check the parent symbol
  directly using SymbolFlagsClass
- Use symbolToString() for the error message, which handles both named
  and unnamed classes correctly

Added test case errorInUnnamedClassExpression.ts to verify the fix.
Copilot AI changed the title [WIP] Port changes from PR 62923 Port PR 62923: Fix crash in abstract property checking for unnamed class expressions Dec 23, 2025
Copilot AI requested a review from ahejlsberg December 23, 2025 17:55
@ahejlsberg ahejlsberg marked this pull request as ready for review December 28, 2025 17:46
Copilot AI review requested due to automatic review settings December 28, 2025 17:46
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR ports TypeScript PR #62923, which fixes a crash when checking abstract properties in unnamed class expressions. The compiler previously crashed with a nil pointer dereference when encountering abstract properties in class expressions without names.

Key Changes

  • Modified the abstract property checking logic to use symbol flags instead of class declarations
  • Updated error message generation to use symbolToString which handles both named and unnamed classes
  • Added a comprehensive test case demonstrating the fix

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
internal/checker/checker.go Fixed crash by checking parent symbol flags directly instead of calling GetClassLikeDeclarationOfSymbol, which returns nil for unnamed class expressions. Updated error message to use symbolToString(parentSymbol) for both named and unnamed classes.
testdata/tests/cases/compiler/errorInUnnamedClassExpression.ts Added minimal test case reproducing the crash scenario with an abstract property in an unnamed class expression
testdata/baselines/reference/compiler/errorInUnnamedClassExpression.types Baseline showing expected type information for the test case
testdata/baselines/reference/compiler/errorInUnnamedClassExpression.symbols Baseline showing expected symbol information for the test case
testdata/baselines/reference/compiler/errorInUnnamedClassExpression.errors.txt Baseline showing expected error diagnostics, including the proper error message for abstract property access

@ahejlsberg ahejlsberg added this pull request to the merge queue Dec 28, 2025
Merged via the queue into main with commit aee6f7f Dec 28, 2025
29 checks passed
@ahejlsberg ahejlsberg deleted the copilot/port-pr-62923 branch December 28, 2025 18:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants