Skip to content

fix(tsoptions): don't panic on empty files when AST node is missing - #65082

Open
Timur Vural (timurzvural) wants to merge 1 commit into
microsoft:mainfrom
timurzvural:fix/65079-empty-files-nil-diagnostic
Open

Timur Vural (timurzvural) wants to merge 1 commit into
microsoft:mainfrom
timurzvural:fix/65079-empty-files-nil-diagnostic

Conversation

@timurzvural

Copy link
Copy Markdown

Fixes #65079

Summary

When tsconfig.json is malformed such that the recovered JSON value still has an empty "files" array but the AST no longer has a usable "files" property node (e.g. {"files":[]}]}), reporting TS18002 via CreateDiagnosticForNodeInSourceFile nil-dereferences the missing node and panics.

Use CreateDiagnosticForNodeInSourceFileOrCompilerDiagnostic instead, matching Strada: prefer a node-anchored diagnostic when the property exists, otherwise fall back to a compiler diagnostic.

Test plan

  • {"files":[]}]} — no panic; emits unlocated TS18002 (+ parse errors); exit non-zero
  • {"files":[]} — still emits located TS18002 at the empty array
  • Built tsc from this branch and verified both cases locally

Use CreateDiagnosticForNodeInSourceFileOrCompilerDiagnostic for the
empty "files" list diagnostic so malformed JSON that still recovers an
empty files array falls back to a compiler diagnostic instead of
dereferencing a nil property node.

Fixes microsoft#65079
Copilot AI balanced review requested due to automatic review settings October 31, 2026 23:05
@github-project-automation github-project-automation Bot moved this to Not started in PR Backlog Oct 31, 2026
@typescript-automation typescript-automation Bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Oct 31, 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.

🟡 Changes recommended

The nil-node fallback still needs regression tests verifying that malformed JSON does not cause a panic, TS18002 is unlocated, and parse diagnostics are preserved, while valid empty-files input retains a located TS18002.

1 open issue
What changed in this PR

Fixes #65079 by preventing a compiler panic when malformed tsconfig.json input leaves an empty files array without a usable AST node.

Changes:

  • Uses the existing diagnostic helper to fall back to an unlocated TS18002 when the node is missing, while preserving located diagnostics when available.
  • Adds a comment explaining the parse-recovery case and alignment with Strada.
File Description
tsc/​internal/​tsoptions/​tsconfigparsing.go Uses a nil-safe diagnostic helper for empty files arrays.

Review effort: Balanced

// Prefer a node-anchored diagnostic when the "files" property is present in the AST;
// under parse recovery the raw value can still be an empty array while the property
// node is missing, so fall back to a compiler diagnostic (matches Strada).
errors = append(errors, CreateDiagnosticForNodeInSourceFileOrCompilerDiagnostic(sourceFile.SourceFile, nodeValue, diagnosticMessage, fileName))

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 Uncommitted Bug PR for untriaged, rejected, closed or missing bug

Projects

Status: Not started

Development

Successfully merging this pull request may close these issues.

panic: nil pointer dereference in CreateDiagnosticForNodeInSourceFile for a malformed "files" array in tsconfig.json

3 participants