Skip to content

Port "Check if switch statements are exhaustive when their expressions is generic with a literal type constraint" #1071

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

Andarist
Copy link
Contributor

@Andarist Andarist commented Jun 5, 2025

Verified

This commit was signed with the committer’s verified signature. The key has expired.
andrewbranch Andrew Branch
…s is generic with a literal type constraint"
@Copilot Copilot AI review requested due to automatic review settings June 5, 2025 18:11
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR ports the “exhaustive switch” behavior for generic literal type constraints, addressing #986.

  • Adds a new test case (exhaustiveSwitchStatementsGeneric1.ts) to validate exhaustive switch statements on generic types.
  • Updates baseline reference files (.types and .symbols) to reflect the changes.
  • Adjusts the flow checker in internal/checker/flow.go to use getBaseConstraintOrType for improved type handling.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
testdata/tests/cases/compiler/exhaustiveSwitchStatementsGeneric1.ts Introduces a test case demonstrating exhaustive switch on generic literal type constraints.
testdata/baselines/reference/compiler/exhaustiveSwitchStatementsGeneric1.types Updates type baseline output for the new test.
testdata/baselines/reference/compiler/exhaustiveSwitchStatementsGeneric1.symbols Updates symbol baseline output for the new test.
internal/checker/flow.go Modifies type retrieval to use getBaseConstraintOrType for proper enforcement of exhaustiveness.

@jakebailey jakebailey enabled auto-merge June 5, 2025 21:57
@jakebailey jakebailey closed this Jun 5, 2025
auto-merge was automatically disabled June 5, 2025 23:16

Pull request was closed

@jakebailey jakebailey reopened this Jun 5, 2025
@jakebailey jakebailey enabled auto-merge June 5, 2025 23:23
@jakebailey jakebailey added this pull request to the merge queue Jun 5, 2025
Merged via the queue into microsoft:main with commit bc8ac16 Jun 5, 2025
61 of 105 checks passed
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.

Error in exhaustive switch over generic argument limited to specific literal strings
2 participants