Skip to content

Finalize evolving array types before narrowing in switch clauses - #64814

Open
Mateusz Burzyński (Andarist) wants to merge 2 commits into
microsoft:mainfrom
Andarist:fix-switch-evolving-array-crash
Open

Mateusz Burzyński (Andarist) wants to merge 2 commits into
microsoft:mainfrom
Andarist:fix-switch-evolving-array-crash

Conversation

@Andarist

Copy link
Copy Markdown
Contributor

fixes #64813

Copilot AI balanced review requested due to automatic review settings October 14, 2026 10:29
@github-project-automation github-project-automation Bot moved this to Not started in PR Backlog Oct 14, 2026
@typescript-automation typescript-automation Bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Oct 14, 2026
expr := ast.SkipParentheses(data.SwitchStatement.Expression())
flowType := c.getTypeAtFlowNode(f, flow.Antecedent)
t := flowType.t
nonEvolvingType := c.finalizeEvolvingArrayType(flowType.t)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this just matches the preestablished pattern used by other narrowing~ functions like getTypeAtFlowCondition, getTypeAtFlowCall and co.

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 preservation test does not detect premature finalization because any[] remains assignable to string[].

1 open finding
What changed in this PR

Prevents compiler crashes when switch narrowing encounters evolving array types.

Changes:

  • Finalizes evolving arrays before switch narrowing.
  • Preserves evolving flow types when narrowing is unchanged.
  • Adds compiler regression coverage and baselines.
File Description
tsc/​internal/​checker/​flow.go Safely handles evolving arrays during switch narrowing.
tsc/​testdata/​tests/​cases/​compiler/​narrowSwitchOnEvolvingArrayNoCrash1.ts Adds regression scenarios.
tsc/​testdata/​baselines/​reference/​compiler/​narrowSwitchOnEvolvingArrayNoCrash1.types Records inferred types.
tsc/​testdata/​baselines/​reference/​compiler/​narrowSwitchOnEvolvingArrayNoCrash1.symbols Records symbols.
tsc/​testdata/​baselines/​reference/​compiler/​narrowSwitchOnEvolvingArrayNoCrash1.errors.txt Records diagnostics.

🧠 Review effort: Balanced

Comment thread tsc/testdata/tests/cases/compiler/narrowSwitchOnEvolvingArrayNoCrash1.ts Outdated

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 focused fix follows existing narrowing behavior and includes coverage for both the crash and evolving-array preservation.

0 open findings

1 resolved since last review

🧠 Review effort: Balanced

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.

Crash: Unhandled case in resolveStructuredTypeMembers when switching on an evolving [] array inside a loop

2 participants