mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: check error for comptime call method argument (#13115)
This commit is contained in:
parent
02f791d9fe
commit
4ce6e663bf
7
vlib/v/checker/tests/comptime_call_method_args_err.out
Normal file
7
vlib/v/checker/tests/comptime_call_method_args_err.out
Normal file
@ -0,0 +1,7 @@
|
||||
vlib/v/checker/tests/comptime_call_method_args_err.vv:9:14: cgen error: expected 0 arguments to method S1.method_hello, but got 1
|
||||
7 |
|
||||
8 | $for method in S1.methods {
|
||||
9 | println(s1.$method('yo'))
|
||||
| ~~~~~~~~~~~~~
|
||||
10 | }
|
||||
11 | }
|
15
vlib/v/checker/tests/comptime_call_method_args_err.vv
Normal file
15
vlib/v/checker/tests/comptime_call_method_args_err.vv
Normal file
@ -0,0 +1,15 @@
|
||||
module main
|
||||
|
||||
struct S1 {}
|
||||
|
||||
fn main() {
|
||||
s1 := S1{}
|
||||
|
||||
$for method in S1.methods {
|
||||
println(s1.$method('yo'))
|
||||
}
|
||||
}
|
||||
|
||||
fn (t S1) method_hello() string {
|
||||
return 'Hello'
|
||||
}
|
@ -99,12 +99,17 @@ fn (mut g Gen) comptime_call(mut node ast.ComptimeCall) {
|
||||
}
|
||||
// check argument length and types
|
||||
if m.params.len - 1 != node.args.len && !expand_strs {
|
||||
// do not generate anything if the argument lengths don't match
|
||||
g.writeln('/* skipping ${sym.name}.$m.name due to mismatched arguments list */')
|
||||
// g.writeln('println(_SLIT("skipping ${node.sym.name}.$m.name due to mismatched arguments list"));')
|
||||
// eprintln('info: skipping ${node.sym.name}.$m.name due to mismatched arguments list\n' +
|
||||
//'method.params: $m.params, args: $node.args\n\n')
|
||||
// verror('expected ${m.params.len-1} arguments to method ${node.sym.name}.$m.name, but got $node.args.len')
|
||||
if g.inside_call {
|
||||
g.error('expected ${m.params.len - 1} arguments to method ${sym.name}.$m.name, but got $node.args.len',
|
||||
node.pos)
|
||||
} else {
|
||||
// do not generate anything if the argument lengths don't match
|
||||
g.writeln('/* skipping ${sym.name}.$m.name due to mismatched arguments list */')
|
||||
// g.writeln('println(_SLIT("skipping ${node.sym.name}.$m.name due to mismatched arguments list"));')
|
||||
// eprintln('info: skipping ${node.sym.name}.$m.name due to mismatched arguments list\n' +
|
||||
//'method.params: $m.params, args: $node.args\n\n')
|
||||
// verror('expected ${m.params.len-1} arguments to method ${node.sym.name}.$m.name, but got $node.args.len')
|
||||
}
|
||||
return
|
||||
}
|
||||
// TODO: check argument types
|
||||
|
Loading…
Reference in New Issue
Block a user