Add test cases for args.er

This commit is contained in:
Shunsuke Shibayama 2022-11-29 21:21:44 +09:00
parent 53a165e1b8
commit 99dab80003
4 changed files with 18 additions and 13 deletions

View file

@ -1046,21 +1046,19 @@ impl Context {
} }
nth += 1; nth += 1;
} }
let missing_len = params_len - passed_params.len();
if missing_len > 0 {
let missing_params = subr let missing_params = subr
.non_default_params .non_default_params
.iter() .iter()
.map(|pt| pt.name().cloned().unwrap_or(Str::ever("_"))) .map(|pt| pt.name().cloned().unwrap_or(Str::ever("_")))
.filter(|pt| !passed_params.contains(pt)) .filter(|pt| !passed_params.contains(pt))
.collect(); .collect::<Vec<_>>();
if !missing_params.is_empty() {
return Err(TyCheckErrors::from(TyCheckError::args_missing_error( return Err(TyCheckErrors::from(TyCheckError::args_missing_error(
self.cfg.input.clone(), self.cfg.input.clone(),
line!() as usize, line!() as usize,
callee.loc(), callee.loc(),
&callee.to_string(), &callee.to_string(),
self.caused_by(), self.caused_by(),
missing_len,
missing_params, missing_params,
))); )));
} }

View file

@ -673,11 +673,11 @@ passed keyword args: {kw_args_len}"
loc: Location, loc: Location,
callee_name: &str, callee_name: &str,
caused_by: String, caused_by: String,
missing_len: usize,
missing_params: Vec<Str>, missing_params: Vec<Str>,
) -> Self { ) -> Self {
let name = StyledStr::new(readable_name(callee_name), Some(WARN), Some(ATTR)); 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 vec_cxt = StyledString::new(&fmt_vec(&missing_params), Some(WARN), Some(ATTR));
let missing_len = missing_params.len();
Self::new( Self::new(
ErrorCore::new( ErrorCore::new(
vec![SubMessage::only_loc(loc)], vec![SubMessage::only_loc(loc)],
@ -2380,7 +2380,6 @@ mod test {
loc, loc,
"\"Callee name here\"", "\"Callee name here\"",
caused_by.into(), caused_by.into(),
0,
vec!["sample".into(), "args".into(), "here".into()], vec!["sample".into(), "args".into(), "here".into()],
); );
errors.push(err); errors.push(err);

View file

@ -3,7 +3,7 @@ print! 1, "", sep:="" # OK
print! end:="", sep:="" # OK print! end:="", sep:="" # OK
print! 1, 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 !1, 1 # OK
print! add x:=!1, y:=2 # OK print! add x:=!1, y:=2 # OK
print! add y:=1, x:=!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 # 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 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 "", 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 !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:=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 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

View file

@ -126,7 +126,7 @@ fn exec_addition_err() -> Result<(), ()> {
#[test] #[test]
fn exec_args() -> Result<(), ()> { fn exec_args() -> Result<(), ()> {
expect_failure("tests/should_err/args.er", 13) expect_failure("tests/should_err/args.er", 15)
} }
#[test] #[test]