[ty] Fix CallableTypeOf[…] for bound methods (#20338)
## Summary `CallableTypeOf[bound_method]` would previously bind `self` to the bound method type itself, instead of binding it to the instance type stored inside the bound method type. ## Test Plan Added regression test
This commit is contained in:
@@ -1046,8 +1046,11 @@ impl<'db> Type<'db> {
|
||||
matches!(self, Type::FunctionLiteral(..))
|
||||
}
|
||||
|
||||
pub(crate) const fn is_bound_method(&self) -> bool {
|
||||
matches!(self, Type::BoundMethod(..))
|
||||
pub(crate) const fn into_bound_method(self) -> Option<BoundMethodType<'db>> {
|
||||
match self {
|
||||
Type::BoundMethod(bound_method) => Some(bound_method),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn is_union_of_single_valued(&self, db: &'db dyn Db) -> bool {
|
||||
|
||||
@@ -11040,8 +11040,10 @@ impl<'db> TypeInferenceBuilder<'db, '_> {
|
||||
.expect("`Bindings` should have at least one `CallableBinding`");
|
||||
|
||||
let mut signature_iter = callable_binding.into_iter().map(|binding| {
|
||||
if argument_type.is_bound_method() {
|
||||
binding.signature.bind_self(self.db(), Some(argument_type))
|
||||
if let Some(bound_method) = argument_type.into_bound_method() {
|
||||
binding
|
||||
.signature
|
||||
.bind_self(self.db(), Some(bound_method.self_instance(db)))
|
||||
} else {
|
||||
binding.signature.clone()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user