Skip to content

fix improve enum error suggestion #3128#3145

Open
asukaminato0721 wants to merge 2 commits intofacebook:mainfrom
asukaminato0721:3128
Open

fix improve enum error suggestion #3128#3145
asukaminato0721 wants to merge 2 commits intofacebook:mainfrom
asukaminato0721:3128

Conversation

@asukaminato0721
Copy link
Copy Markdown
Contributor

Summary

Fixes #3128

The change teaches call-argument diagnostics to suggest an enum member when the provided raw literal exactly matches a single expected enum value.

Test Plan

add test

@github-actions

This comment has been minimized.

@asukaminato0721 asukaminato0721 marked this pull request as ready for review April 15, 2026 09:37
Copilot AI review requested due to automatic review settings April 15, 2026 09:37
Copy link
Copy Markdown

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

Adds enum-member “did you mean …” suggestions to call-argument type mismatch diagnostics when a provided literal exactly matches an enum’s underlying value (fixing #3128).

Changes:

  • Add enum-value → enum-member suggestion helper in enum handling code.
  • Extend call-argument type-check error reporting to append an enum-member suggestion line when applicable.
  • Add a regression test covering StrEnum argument mismatch suggestions.

Reviewed changes

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

File Description
pyrefly/lib/test/enums.rs Adds regression test asserting the new call-argument suggestion text for StrEnum.
pyrefly/lib/alt/class/enums.rs Implements logic to map a raw literal type to a unique enum member suggestion.
pyrefly/lib/alt/answers_solver.rs Injects enum-member suggestion lines into call-argument diagnostics during check_type failures.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pyrefly/lib/alt/class/enums.rs Outdated
Comment thread pyrefly/lib/alt/class/enums.rs Outdated
Comment thread pyrefly/lib/alt/answers_solver.rs Outdated
Copy link
Copy Markdown
Contributor

@rchen152 rchen152 left a comment

Choose a reason for hiding this comment

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

The Copilot feedback looks legitimate here - specifically, the concerns about union handling and code duplication.

@github-actions github-actions Bot added size/m and removed size/m labels Apr 16, 2026
@github-actions
Copy link
Copy Markdown

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

improve enum error suggestion

3 participants