Skip to content

Commit

Permalink
fix: ignore too many args error
Browse files Browse the repository at this point in the history
  • Loading branch information
mtshiba committed Oct 11, 2023
1 parent 22096ce commit 3f4520d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
17 changes: 14 additions & 3 deletions crates/erg_compiler/context/inquire.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1614,11 +1614,17 @@ impl Context {
} else {
obj.clone()
};
let params_len = subr.non_default_params.len() + subr.default_params.len();
let params_len = if is_method {
subr.non_default_params.len().saturating_sub(1) + subr.default_params.len()
} else {
subr.non_default_params.len() + subr.default_params.len()
};
if (params_len < pos_args.len() || params_len < pos_args.len() + kw_args.len())
&& subr.var_params.is_none()
{
return Err(self.gen_too_many_args_error(&callee, subr, pos_args, kw_args));
return Err(
self.gen_too_many_args_error(&callee, subr, is_method, pos_args, kw_args)
);
}
let mut passed_params = set! {};
let non_default_params = if is_method {
Expand Down Expand Up @@ -1833,6 +1839,7 @@ impl Context {
&self,
callee: &hir::Expr,
subr_ty: &SubrType,
is_method: bool,
pos_args: &[hir::PosArg],
kw_args: &[hir::KwArg],
) -> TyCheckErrors {
Expand Down Expand Up @@ -1863,7 +1870,11 @@ impl Context {
}
}
if unknown_args.is_empty() && duplicated_args.is_empty() {
let params_len = subr_ty.non_default_params.len() + subr_ty.default_params.len();
let params_len = if is_method {
subr_ty.non_default_params.len().saturating_sub(1) + subr_ty.default_params.len()
} else {
subr_ty.non_default_params.len() + subr_ty.default_params.len()
};
TyCheckErrors::from(TyCheckError::too_many_args_error(
self.cfg.input.clone(),
line!() as usize,
Expand Down
4 changes: 4 additions & 0 deletions tests/should_err/args.er
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,7 @@ print! sub 1, 1, y:=2 # ERR, too many args

for! {"a": 1}, (i, s #[ ERR ]#) =>
print! i

d = !{ "a": 1 }
d.insert! "b", 2, 3 # ERR, too many args
d.insert! "c" # ERR, missing argument value
2 changes: 1 addition & 1 deletion tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ fn exec_addition_err() -> Result<(), ()> {

#[test]
fn exec_args() -> Result<(), ()> {
expect_failure("tests/should_err/args.er", 0, 17)
expect_failure("tests/should_err/args.er", 0, 19)
}

#[test]
Expand Down

0 comments on commit 3f4520d

Please sign in to comment.