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
9 changes: 8 additions & 1 deletion pyrefly/lib/alt/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -947,10 +947,17 @@ impl<'a, Ans: LookupAnswer> AnswersSolver<'a, Ans> {
)
)
);
let quantified_bound = match &param_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(&param_ty);
let check: Option<(&Type, &dyn Fn() -> TypeCheckContext)> = if skip_check {
None
} else {
Some((&param_ty, &make_context))
Some((check_ty, &make_context))
};
let required = self.get_requiredness(default, check, stub_or_impl, errors);
(param_ty, required, false)
Expand Down
15 changes: 15 additions & 0 deletions pyrefly/lib/test/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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#"
Expand Down
Loading