Skip to content

Commit 98d87b6

Browse files
stroxlermeta-codesync[bot]
authored andcommitted
Add some more TypeVar-only test cases
Summary: **This stack** Adds a "callable residual" type that allows us to capture structure when a generic or overloaded callable is passed to a higher-order function. The residuals can later be "exploded" to recover generic and overload structure in outputs (either Callable outputs, or classes whose methods capture the callable structure of an argument - e.g. callback protocol classes). The full design details are [here](https://github.com/stroxler/pyrefly-docs/tree/main/callable-residuals) **This diff** Agents, as they tend to do, implemented an initial solution to residual handling that *shared absolutely no logic* with a correct answer but happened to work on the test suite because all test cases involved an input that was generic in a single type parameter that it returned. This commit adds some more test cases where we have multiple type parameters and/or the return type is concrete. This will make the test harness more robust against completely incorrect implementations. Reviewed By: rchen152 Differential Revision: D102011891 fbshipit-source-id: 8fcfab9052427d24a940c5c2a00dda9e485ef1be
1 parent 35dab99 commit 98d87b6

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

pyrefly/lib/test/callable_residuals.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,34 @@ reveal_type(result) # E: revealed type: (int, Unknown) -> Unknown
6262
"#,
6363
);
6464

65+
testcase!(
66+
bug = "Residual marker recovery incorrectly depends on return-position quantifieds",
67+
test_generic_residual_concrete_return,
68+
r#"
69+
from typing import Callable, reveal_type
70+
def higher_order[A, B](x: Callable[[A, B], int]) -> Callable[[A, B], int]:
71+
return x
72+
def generic_fn[T](x: T, y: T) -> int:
73+
return 0
74+
result = higher_order(generic_fn)
75+
reveal_type(result) # E: revealed type: (Unknown, Unknown) -> int
76+
"#,
77+
);
78+
79+
testcase!(
80+
bug = "Distinct residual positions collapse to one solved variable in higher-order matching",
81+
test_generic_residual_distinct_positions,
82+
r#"
83+
from typing import Callable, reveal_type
84+
def higher_order[A, B](x: Callable[[A, B], B]) -> Callable[[A, B], B]:
85+
return x
86+
def generic_fn[T, S](x: S, y: T) -> T:
87+
return y
88+
result = higher_order(generic_fn)
89+
reveal_type(result) # E: revealed type: (Unknown, Unknown) -> Unknown
90+
"#,
91+
);
92+
6593
testcase!(
6694
bug = "Generic functions don't work with ParamSpec",
6795
test_param_spec_generic_function,

0 commit comments

Comments
 (0)