1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

cgen: check call argument on methods (#12965)

This commit is contained in:
pancake 2021-12-26 10:53:56 +01:00 committed by GitHub
parent 3b5de71e60
commit 04be2465dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 0 deletions

View File

@ -654,7 +654,14 @@ pub fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool)
node.expected_arg_types << param.typ node.expected_arg_types << param.typ
} }
} }
if !c.pref.backend.is_js() && node.args.len > 0 && func.params.len == 0 {
c.error('too many arguments in call to `$func.name` (non-js backend: $c.pref.backend)',
node.pos)
}
for i, mut call_arg in node.args { for i, mut call_arg in node.args {
if func.params.len == 0 {
continue
}
param := if func.is_variadic && i >= func.params.len - 1 { param := if func.is_variadic && i >= func.params.len - 1 {
func.params[func.params.len - 1] func.params[func.params.len - 1]
} else { } else {

View File

@ -0,0 +1,5 @@
vlib/v/checker/tests/js_with_non_js_backend_too_many_arguments.vv:3:4: error: too many arguments in call to `JS.Foo.bar` (non-js backend: c)
1 | fn JS.Foo.bar() bool
2 |
3 | JS.Foo.bar(123)
| ~~~~~~~~~~~~

View File

@ -0,0 +1,3 @@
fn JS.Foo.bar() bool
JS.Foo.bar(123)