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
4 changes: 4 additions & 0 deletions pyrefly/lib/solver/subset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1791,6 +1791,10 @@ impl<'a, Ans: LookupAnswer> Subset<'a, Ans> {
// Therefore try these quantified cases, but only pick them if they work.
(Type::Quantified(q), u)
if let Restriction::Bound(bound) = q.restriction()
// A bare inference variable can preserve the quantified type itself. Expanding
// it to its bound here would make inference depend on which argument is checked
// first (https://github.com/facebook/pyrefly/issues/4187).
&& !matches!(u, Type::Union(union) if union.members.iter().any(|t| matches!(t, Type::Var(_))))
&& self
.solver
.with_snapshot(&u.collect_maybe_placeholder_vars(), || {
Expand Down
24 changes: 24 additions & 0 deletions pyrefly/lib/test/generic_basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,30 @@ assert_type(bad(Sub), Sub)
"#,
);

// Regression test for https://github.com/facebook/pyrefly/issues/4187
testcase!(
test_generic_keyword_inference_is_order_independent,
r#"
class P: ...

class Controller[T: P]:
value: T

def target[T: P](
value: T | None = None,
*,
controller: Controller[T] | None = None,
) -> None: ...

def caller[T: P](
value: T | None,
controller: Controller[T] | None,
) -> None:
target(value=value, controller=controller)
target(controller=controller, value=value)
"#,
);

testcase!(
test_generic_alias_fields,
r#"
Expand Down
Loading