Repository navigation
fix: Fix nil pointer panic in getLateBoundSymbol under --noCheck - #64731
Andre Fajar N (andre-fajar-n) wants to merge 4 commits into
Conversation
There was a problem hiding this comment.
🟢 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.
|
@microsoft-github-policy-service agree |
| // Parent can be nil for top-level script expandos (SourceFile has no symbol) when | ||
| // checking was skipped (--noCheck) and late binding has not run yet. |
There was a problem hiding this comment.
Doesn't this imply we should have done something earlier? Just adding a nil check seems wrong.
There was a problem hiding this comment.
I will check it again
There was a problem hiding this comment.
I had already updated the changes. Please check it again Jake Bailey (@jakebailey)
Co-authored-by: Cursor <cursoragent@cursor.com>
Fixes #64669
Analysis
With
--declaration --emitDeclarationOnly --noCheck, declaration emit can force late binding for a computed expando assignmentlike:
In that path,
getLateBoundSymbolcallsgetMembersOfSymbol/getExportsOfSymbolon the symbol's parent. For a top-levelscript, the parent can be nil (the SourceFile has no symbol), which panics:
panic: runtime error: invalid memory address or nil pointer dereferenceWithout
--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 existinglateSymbol = symbolfallback instead of dereferencing nil.Added compiler test
noCheckExpandoElementAccessAssignmentcovering this flags + repro combination.Notes
AI-assisted change (Cursor); I reviewed and verified the patch locally against the repro and the new harness test.