Skip to content

fix: Fix nil pointer panic in getLateBoundSymbol under --noCheck - #64731

Open
Andre Fajar N (andre-fajar-n) wants to merge 1 commit into
microsoft:mainfrom
andre-fajar-n:fix/nocheck-latebound-nil-parent
Open

Andre Fajar N (andre-fajar-n) wants to merge 1 commit into
microsoft:mainfrom
andre-fajar-n:fix/nocheck-latebound-nil-parent

Conversation

@andre-fajar-n

Copy link
Copy Markdown

Fixes #64669

Analysis

With --declaration --emitDeclarationOnly --noCheck, declaration emit can force late binding for a computed expando assignment
like:

const k = "bar";
foo[k] = 1;
function foo() {}

In that path, getLateBoundSymbol calls getMembersOfSymbol / getExportsOfSymbol on the symbol's parent. For a top-level
script, the parent can be nil (the SourceFile has no symbol), which panics:
panic: runtime error: invalid memory address or nil pointer dereference
Without --noCheck, checking usually late-binds earlier, so the nil parent path is less likely to be hit.

Fix

Guard on a non-nil parent before forcing late binding in getLateBoundSymbol. If the parent is nil, fall through to the existing
lateSymbol = symbol fallback instead of dereferencing nil.
Added compiler test noCheckExpandoElementAccessAssignment covering this flags + repro combination.

Notes

AI-assisted change (Cursor); I reviewed and verified the patch locally against the repro and the new harness test.

Copilot AI balanced review requested due to automatic review settings October 11, 2026 03:44
@typescript-automation typescript-automation Bot added the For Backlog Bug PRs that fix a backlog bug label Oct 11, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The targeted nil guard resolves the reported panic and is covered by an appropriate compiler regression test.

0 open findings

What changed in this PR

Fixes a nil-pointer panic during declaration-only emit with --noCheck for top-level computed expando assignments.

Changes:

  • Guards late binding when the symbol parent is nil.
  • Adds a compiler regression test and output baselines.
File Description
tsc/​internal/​checker/​checker.go Prevents dereferencing a nil parent during late binding.
tsc/​testdata/​tests/​cases/​compiler/​noCheckExpandoElementAccessAssignment.ts Adds the regression case.
tsc/​testdata/​baselines/​reference/​compiler/​noCheckExpandoElementAccessAssignment.js Captures declaration emit.
tsc/​testdata/​baselines/​reference/​compiler/​noCheckExpandoElementAccessAssignment.symbols Captures symbol output.
tsc/​testdata/​baselines/​reference/​compiler/​noCheckExpandoElementAccessAssignment.types Captures inferred types.

🧠 Review effort: Balanced


💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

@andre-fajar-n

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

For Backlog Bug PRs that fix a backlog bug

Projects

Status: Not started

Development

Successfully merging this pull request may close these issues.

runtime error: invalid memory address or nil pointer dereference in getMembersOfSymbol

2 participants