diff --git a/pyrefly/lib/alt/function.rs b/pyrefly/lib/alt/function.rs index efad7d3617..d4f18278da 100644 --- a/pyrefly/lib/alt/function.rs +++ b/pyrefly/lib/alt/function.rs @@ -947,10 +947,17 @@ impl<'a, Ans: LookupAnswer> AnswersSolver<'a, Ans> { ) ) ); + let quantified_bound = match ¶m_ty { + Type::Quantified(q) if q.is_type_var() => { + Some(q.bound_type(self.stdlib, self.heap)) + } + _ => None, + }; + let check_ty = quantified_bound.as_ref().unwrap_or(¶m_ty); let check: Option<(&Type, &dyn Fn() -> TypeCheckContext)> = if skip_check { None } else { - Some((¶m_ty, &make_context)) + Some((check_ty, &make_context)) }; let required = self.get_requiredness(default, check, stub_or_impl, errors); (param_ty, required, false) diff --git a/pyrefly/lib/test/simple.rs b/pyrefly/lib/test/simple.rs index 44fab23ef4..52bcb2e82e 100644 --- a/pyrefly/lib/test/simple.rs +++ b/pyrefly/lib/test/simple.rs @@ -1999,6 +1999,21 @@ def f(x: int = "test"): # E: Default `Literal['test']` is not assignable to para "#, ); +testcase!( + test_parameter_default_typevar_bound, + r#" +from typing import Literal, TypeVar + +T = TypeVar("T", bound=Literal["foo"]) + +def ok(t: T = "foo") -> None: + pass + +def bad(t: T = "bar") -> None: # E: Default `Literal['bar']` is not assignable to parameter `t` with type `Literal['foo']` + pass +"#, +); + testcase!( test_parameter_default_infer, r#"