fix: __call__ overload bug

This commit is contained in:
Shunsuke Shibayama 2024-08-13 13:02:14 +09:00
parent b87f3da3c6
commit b21d018adf
2 changed files with 24 additions and 2 deletions

View file

@ -1848,6 +1848,11 @@ impl Context {
res res
} }
} }
Type::And(_, _) => {
let instance =
self.resolve_overload(obj, instance.clone(), pos_args, kw_args, &obj)?;
self.substitute_call(obj, attr_name, &instance, pos_args, kw_args, namespace)
}
Type::Failure => Ok(SubstituteResult::Ok), Type::Failure => Ok(SubstituteResult::Ok),
_ => { _ => {
self.substitute_dunder_call(obj, attr_name, instance, pos_args, kw_args, namespace) self.substitute_dunder_call(obj, attr_name, instance, pos_args, kw_args, namespace)
@ -2095,7 +2100,13 @@ impl Context {
)?; )?;
} }
let instance = self.instantiate_def_type(&call_vi.t)?; let instance = self.instantiate_def_type(&call_vi.t)?;
self.substitute_call(obj, attr_name, &instance, pos_args, kw_args, namespace)?; let instance = match self
.substitute_call(obj, attr_name, &instance, pos_args, kw_args, namespace)?
{
SubstituteResult::__Call__(instance)
| SubstituteResult::Coerced(instance) => instance,
SubstituteResult::Ok => instance,
};
return Ok(SubstituteResult::__Call__(instance)); return Ok(SubstituteResult::__Call__(instance));
} }
// instance method __call__ // instance method __call__
@ -2106,7 +2117,14 @@ impl Context {
}) })
{ {
let instance = self.instantiate_def_type(&call_vi.t)?; let instance = self.instantiate_def_type(&call_vi.t)?;
self.substitute_call(obj, attr_name, &instance, pos_args, kw_args, namespace)?; let instance = match self
.substitute_call(obj, attr_name, &instance, pos_args, kw_args, namespace)?
{
SubstituteResult::__Call__(instance) | SubstituteResult::Coerced(instance) => {
instance
}
SubstituteResult::Ok => instance,
};
return Ok(SubstituteResult::__Call__(instance)); return Ok(SubstituteResult::__Call__(instance));
} }
} }

View file

@ -13,3 +13,7 @@ assert func() == "foo"
assert module::__file__.endswith "dunder.er" assert module::__file__.endswith "dunder.er"
assert C.new().__file__ == "bar" assert C.new().__file__ == "bar"
assert imp.func().endswith "import.er" assert imp.func().endswith "import.er"
discard Str()
discard Str(1)
discard Str(bytes("aaa", "utf-8"), "utf-8")