Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions pyrefly/lib/solver/subset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1268,9 +1268,23 @@ impl<'a, Ans: LookupAnswer> Subset<'a, Ans> {
}
(Type::Quantified(q), u)
if let Restriction::Constraints(constraints) = q.restriction()
&& constraints
.iter()
.all(|constraint| self.is_subset_eq(constraint, u).is_ok()) =>
&& constraints.iter().all(|constraint| {
// When u is a union containing solver variables, check each
// constraint only against concrete (non-var) members. The
// `.all()` iterator can partially pin vars: e.g. for AnyStr
// <: Var(T) | None, `str <: Var(T)` pins T=str, then `bytes
// <: str|None` fails, leaving T irreversibly pinned to str.
if let Type::Union(box Union { members, .. }) = u
&& u.may_contain_quantified_var()
{
members
.iter()
.filter(|m| !m.may_contain_quantified_var())
.any(|m| self.is_subset_eq(constraint, m).is_ok())
} else {
self.is_subset_eq(constraint, u).is_ok()
}
}) =>
{
Ok(())
}
Expand Down
3 changes: 1 addition & 2 deletions pyrefly/lib/test/generic_restrictions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1213,7 +1213,6 @@ assert_type(f(b"hi"), bytes)
);

testcase!(
bug = "Should not produce a type error; https://github.com/facebook/pyrefly/issues/2644",
test_anystr_none_passthrough_classmethod,
r#"
from typing import AnyStr
Expand All @@ -1223,7 +1222,7 @@ class A:
def create(cls, x: AnyStr | None): ...

def test(x: AnyStr | None):
A.create(x) # E: Argument `AnyStr | None` is not assignable to parameter `x` with type `str | None` in function `A.create`
A.create(x)
"#,
);

Expand Down
Loading