diff --git a/pyrefly/lib/alt/unwrap.rs b/pyrefly/lib/alt/unwrap.rs index a65f6fe395..5d90496993 100644 --- a/pyrefly/lib/alt/unwrap.rs +++ b/pyrefly/lib/alt/unwrap.rs @@ -299,7 +299,19 @@ impl<'a, Ans: LookupAnswer> AnswersSolver<'a, Ans> { .heap .mk_class_type(self.stdlib.list(elem.to_type(self.heap))); if self.is_subset_eq(&list_type, hint) { - self.resolve_var_opt(hint, elem) + let elem = self.resolve_var_opt(hint, elem); + // A bounded call type variable may only decompose to the `Any` in its bound. In that + // case the unhinted list type provides the useful constraint for solving the call. + if elem.as_ref().is_some_and(Type::is_any) + && hint + .collect_maybe_placeholder_vars() + .into_iter() + .any(|var| self.solver().var_is_quantified(var)) + { + None + } else { + elem + } } else { None } diff --git a/pyrefly/lib/test/calls.rs b/pyrefly/lib/test/calls.rs index c1dbec79c9..b87d448475 100644 --- a/pyrefly/lib/test/calls.rs +++ b/pyrefly/lib/test/calls.rs @@ -324,6 +324,15 @@ reduce(max, [1,2]) "#, ); +testcase!( + test_iter_list_literal, + r#" +from typing import Iterator, assert_type + +assert_type(iter([0]), Iterator[int]) + "#, +); + testcase!( test_call_arg_lambda_contextual_typing, r#"