Skip to content

Fix nil pointer dereference in explainRedirectAndImpliedFormat during diagnostics#3377

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/fix-nil-pointer-dereference-again
Draft

Fix nil pointer dereference in explainRedirectAndImpliedFormat during diagnostics#3377
Copilot wants to merge 2 commits intomainfrom
copilot/fix-nil-pointer-dereference-again

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 9, 2026

explainRedirectAndImpliedFormat panics when GetSourceFileByPath returns nil for a given path. The nil *ast.SourceFile gets assigned to an ast.HasFileName interface (making it non-nil), then file.Path() dereferences the nil concrete value.

TypeScript guards this with file && explainIfFileIsRedirectAndImpliedFormat(...) in programDiagnostics.ts:229. The Go port was missing this check.

  • Return early with cached nil diagnostics when sourceFile is nil, using the same LoadOrStore caching pattern as the rest of the function

…source file not found

When neither a redirect file nor a source file exists for a given path,
explainRedirectAndImpliedFormat would call methods on a nil *ast.SourceFile
wrapped in an ast.HasFileName interface, causing a nil pointer dereference.

This matches TypeScript's guard (file && explainIfFileIsRedirectAndImpliedFormat)
in programDiagnostics.ts:229.

Agent-Logs-Url: https://github.com/microsoft/typescript-go/sessions/be0523e7-9024-4d28-86bd-5992602b606c

Co-authored-by: DanielRosenwasser <972891+DanielRosenwasser@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix nil pointer dereference during diagnostics request Fix nil pointer dereference in explainRedirectAndImpliedFormat during diagnostics Apr 9, 2026
Copilot AI requested a review from DanielRosenwasser April 9, 2026 19:16
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.

nil pointer dereference during diagnostics request

2 participants