From 05c654f71591fd54f03917e90039f1cb88c49bff Mon Sep 17 00:00:00 2001 From: kousei yamashita Date: Wed, 13 Dec 2023 13:01:44 +0900 Subject: [PATCH] Update validate_argument_length to catch fewer argumetns error --- lib/skc_ast2hir/src/convert_exprs/method_call.rs | 2 +- tests/erroneous/method_call/fewer_argument_error.sk | 6 ++++++ ...ous__erroneous@method_call__fewer_argument_error.sk.snap | 6 ++++++ 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 tests/erroneous/method_call/fewer_argument_error.sk create mode 100644 tests/snapshots/erroneous__erroneous@method_call__fewer_argument_error.sk.snap diff --git a/lib/skc_ast2hir/src/convert_exprs/method_call.rs b/lib/skc_ast2hir/src/convert_exprs/method_call.rs index cfc2f52b..4d87c497 100644 --- a/lib/skc_ast2hir/src/convert_exprs/method_call.rs +++ b/lib/skc_ast2hir/src/convert_exprs/method_call.rs @@ -168,7 +168,7 @@ pub fn arrange_named_args<'a>( /// Check if number of arguments matches to the params. fn validate_argument_length(total_args: usize, params: &[MethodParam]) -> Result<()> { - if total_args > params.len() { + if total_args != params.len() { return Err(error::argument_error(format!( "wrong number of arguments: expected {}, got {}", params.len(), diff --git a/tests/erroneous/method_call/fewer_argument_error.sk b/tests/erroneous/method_call/fewer_argument_error.sk new file mode 100644 index 00000000..1c88ab85 --- /dev/null +++ b/tests/erroneous/method_call/fewer_argument_error.sk @@ -0,0 +1,6 @@ +class A + def self.run(n: Int) + p n + end +end +A.run diff --git a/tests/snapshots/erroneous__erroneous@method_call__fewer_argument_error.sk.snap b/tests/snapshots/erroneous__erroneous@method_call__fewer_argument_error.sk.snap new file mode 100644 index 00000000..63ad26a0 --- /dev/null +++ b/tests/snapshots/erroneous__erroneous@method_call__fewer_argument_error.sk.snap @@ -0,0 +1,6 @@ +--- +source: tests/erroneous.rs +expression: compiler_output +input_file: tests/erroneous/method_call/fewer_argument_error.sk +--- +wrong number of arguments: expected 1, got 0