Skip to content

fix Constrained TypeVar lost after binop #3220#3242

Open
asukaminato0721 wants to merge 1 commit intofacebook:mainfrom
asukaminato0721:3220
Open

fix Constrained TypeVar lost after binop #3220#3242
asukaminato0721 wants to merge 1 commit intofacebook:mainfrom
asukaminato0721:3220

Conversation

@asukaminato0721
Copy link
Copy Markdown
Contributor

@asukaminato0721 asukaminato0721 commented Apr 25, 2026

Summary

Fixes #3220

constrained TypeVar binary ops preserve the original quantified T when evaluating over constraints produces the same constraint set.

Test Plan

add test

@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. ✅

@asukaminato0721 asukaminato0721 marked this pull request as ready for review April 25, 2026 19:00
Copilot AI review requested due to automatic review settings April 25, 2026 19:00
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

Fixes a type inference bug in Pyrefly where constrained TypeVars could be widened to their constraint union after binary operations, leading to false-positive operator errors (issue #3220).

Changes:

  • Add a regression test covering constrained TypeVar preservation through chained binops.
  • Preserve constrained TypeVar quantification in binop_types when the computed result matches the TypeVar’s constraint union.

Reviewed changes

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

File Description
pyrefly/lib/test/operators.rs Adds a regression testcase reproducing the constrained-TypeVar binop scenario from #3220.
pyrefly/lib/alt/operators.rs Adjusts binop type computation to keep constrained TypeVars quantified when binop results equal their constraint union.

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

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.

Constrained TypeVar lost after binop

2 participants