mirror of
https://github.com/erg-lang/erg.git
synced 2025-09-29 04:24:43 +00:00
Fix method call bug
This commit is contained in:
parent
a0b2917359
commit
aa2b45bf86
15 changed files with 106 additions and 101 deletions
|
@ -924,7 +924,7 @@ impl UnaryOp {
|
|||
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
||||
pub struct Call {
|
||||
pub obj: Box<Expr>,
|
||||
pub method_name: Option<Identifier>,
|
||||
pub attr_name: Option<Identifier>,
|
||||
pub args: Args,
|
||||
}
|
||||
|
||||
|
@ -935,8 +935,8 @@ impl NestedDisplay for Call {
|
|||
} else {
|
||||
write!(f, "{}", self.obj)?;
|
||||
}
|
||||
if let Some(method_name) = self.method_name.as_ref() {
|
||||
write!(f, "{}", method_name)?;
|
||||
if let Some(attr_name) = self.attr_name.as_ref() {
|
||||
write!(f, "{}", attr_name)?;
|
||||
}
|
||||
writeln!(f, ":")?;
|
||||
self.args.fmt_nest(f, level + 1)
|
||||
|
@ -952,10 +952,10 @@ impl Locational for Call {
|
|||
}
|
||||
|
||||
impl Call {
|
||||
pub fn new(obj: Expr, method_name: Option<Identifier>, args: Args) -> Self {
|
||||
pub fn new(obj: Expr, attr_name: Option<Identifier>, args: Args) -> Self {
|
||||
Self {
|
||||
obj: Box::new(obj),
|
||||
method_name,
|
||||
attr_name,
|
||||
args,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -181,7 +181,7 @@ impl Desugarer {
|
|||
})
|
||||
.collect();
|
||||
let args = Args::new(pos_args, kw_args, paren);
|
||||
Expr::Call(Call::new(obj, call.method_name, args))
|
||||
Expr::Call(Call::new(obj, call.attr_name, args))
|
||||
}
|
||||
Expr::Def(def) => {
|
||||
let mut chunks = vec![];
|
||||
|
|
|
@ -1415,11 +1415,11 @@ impl Parser {
|
|||
let mut call_or_acc = self.try_reduce_acc_chain(acc, in_type_args)?;
|
||||
while let Some(res) = self.opt_reduce_args(in_type_args) {
|
||||
let args = res.map_err(|_| self.stack_dec())?;
|
||||
let (receiver, method_name) = match call_or_acc {
|
||||
let (receiver, attr_name) = match call_or_acc {
|
||||
Expr::Accessor(Accessor::Attr(attr)) => (*attr.obj, Some(attr.ident)),
|
||||
other => (other, None),
|
||||
};
|
||||
let call = Call::new(receiver, method_name, args);
|
||||
let call = Call::new(receiver, attr_name, args);
|
||||
call_or_acc = Expr::Call(call);
|
||||
}
|
||||
self.level -= 1;
|
||||
|
@ -1529,11 +1529,11 @@ impl Parser {
|
|||
}
|
||||
Some(t) if t.is(LParen) && obj.col_end() == t.col_begin() => {
|
||||
let args = self.try_reduce_args(false).map_err(|_| self.stack_dec())?;
|
||||
let (receiver, method_name) = match obj {
|
||||
let (receiver, attr_name) = match obj {
|
||||
Expr::Accessor(Accessor::Attr(attr)) => (*attr.obj, Some(attr.ident)),
|
||||
other => (other, None),
|
||||
};
|
||||
let call = Call::new(receiver, method_name, args);
|
||||
let call = Call::new(receiver, attr_name, args);
|
||||
obj = Expr::Call(call);
|
||||
}
|
||||
Some(t) if t.is(VBar) && !in_type_args => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue