diff --git a/compiler/erg_compiler/context/inquire.rs b/compiler/erg_compiler/context/inquire.rs index b0d28c8d..dd3ba304 100644 --- a/compiler/erg_compiler/context/inquire.rs +++ b/compiler/erg_compiler/context/inquire.rs @@ -1046,21 +1046,19 @@ impl Context { } nth += 1; } - let missing_len = params_len - passed_params.len(); - if missing_len > 0 { - let missing_params = subr - .non_default_params - .iter() - .map(|pt| pt.name().cloned().unwrap_or(Str::ever("_"))) - .filter(|pt| !passed_params.contains(pt)) - .collect(); + let missing_params = subr + .non_default_params + .iter() + .map(|pt| pt.name().cloned().unwrap_or(Str::ever("_"))) + .filter(|pt| !passed_params.contains(pt)) + .collect::>(); + if !missing_params.is_empty() { return Err(TyCheckErrors::from(TyCheckError::args_missing_error( self.cfg.input.clone(), line!() as usize, callee.loc(), &callee.to_string(), self.caused_by(), - missing_len, missing_params, ))); } diff --git a/compiler/erg_compiler/error.rs b/compiler/erg_compiler/error.rs index cf3a2147..d6243817 100644 --- a/compiler/erg_compiler/error.rs +++ b/compiler/erg_compiler/error.rs @@ -673,11 +673,11 @@ passed keyword args: {kw_args_len}" loc: Location, callee_name: &str, caused_by: String, - missing_len: usize, missing_params: Vec, ) -> Self { let name = StyledStr::new(readable_name(callee_name), Some(WARN), Some(ATTR)); let vec_cxt = StyledString::new(&fmt_vec(&missing_params), Some(WARN), Some(ATTR)); + let missing_len = missing_params.len(); Self::new( ErrorCore::new( vec![SubMessage::only_loc(loc)], @@ -2380,7 +2380,6 @@ mod test { loc, "\"Callee name here\"", caused_by.into(), - 0, vec!["sample".into(), "args".into(), "here".into()], ); errors.push(err); diff --git a/tests/should_err/args.er b/tests/should_err/args.er index 6addfb87..82a9006d 100644 --- a/tests/should_err/args.er +++ b/tests/should_err/args.er @@ -3,7 +3,7 @@ print! 1, "", sep:="" # OK print! end:="", sep:="" # OK print! 1, end:="", sep:="" # OK -add x: Int!, y: Int = x - y +add x: Int!, y: Int = x + y print! add !1, 1 # OK print! add x:=!1, y:=2 # OK print! add y:=1, x:=!2 # OK @@ -16,6 +16,14 @@ print! add x:=!1, y:=2, z:=1 # ERR, z is unexpected print! add x:=!1, y:=2, x:=!2 # ERR, x is passed twice print! add x:=!1, y:=2, x:=!2, z:=1 # ERR, x is passed twice, z is unexpected print! add "", y:=1 # ERR, the type of x is wrong +print! add !1, 1, 1 # ERR, too many args print! add !1, 1, y:=1 # ERR, too many args print! add "", y:=1, x:=1 # ERR, the type of x is wrong, x is passed twice (or args are too many) print! add "", y:="" # ERR, the types of x, y are wrong + +sub x: Int!, y: Int := 0 = x - y +print! sub !1 # OK +print! sub !1, 1 # OK +print! sub x:=!1, y:=2 # OK +print! sub x:=!1 # OK +print! sub !1, 1, y:=2 # ERR, too many args diff --git a/tests/test.rs b/tests/test.rs index 0b89f84f..b255a836 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -126,7 +126,7 @@ fn exec_addition_err() -> Result<(), ()> { #[test] fn exec_args() -> Result<(), ()> { - expect_failure("tests/should_err/args.er", 13) + expect_failure("tests/should_err/args.er", 15) } #[test]