mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: check fn call using 'none' as argument (#17070)
This commit is contained in:
parent
ddf3909fed
commit
b2dac566b0
@ -1019,6 +1019,9 @@ fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool) ast.
|
||||
}
|
||||
}
|
||||
arg_typ_sym := c.table.sym(arg_typ)
|
||||
if arg_typ_sym.kind == .none_ {
|
||||
c.error('cannot use `none` as function argument', call_arg.pos)
|
||||
}
|
||||
param_typ_sym := c.table.sym(param.typ)
|
||||
if func.is_variadic && arg_typ.has_flag(.variadic) && node.args.len - 1 > i {
|
||||
c.error('when forwarding a variadic variable, it must be the final argument',
|
||||
@ -1748,6 +1751,9 @@ fn (mut c Checker) method_call(mut node ast.CallExpr) ast.Type {
|
||||
}
|
||||
continue
|
||||
}
|
||||
if final_arg_sym.kind == .none_ {
|
||||
c.error('cannot use `none` as method argument', arg.pos)
|
||||
}
|
||||
if param.typ.is_ptr() && !arg.typ.is_real_pointer() && arg.expr.is_literal()
|
||||
&& !c.pref.translated {
|
||||
c.error('literal argument cannot be passed as reference parameter `${c.table.type_to_str(param.typ)}`',
|
||||
|
6
vlib/v/checker/tests/fn_call_using_none_arg_err.out
Normal file
6
vlib/v/checker/tests/fn_call_using_none_arg_err.out
Normal file
@ -0,0 +1,6 @@
|
||||
vlib/v/checker/tests/fn_call_using_none_arg_err.vv:6:4: error: cannot use `none` as function argument
|
||||
4 |
|
||||
5 | fn main() {
|
||||
6 | f(none)
|
||||
| ~~~~
|
||||
7 | }
|
7
vlib/v/checker/tests/fn_call_using_none_arg_err.vv
Normal file
7
vlib/v/checker/tests/fn_call_using_none_arg_err.vv
Normal file
@ -0,0 +1,7 @@
|
||||
fn f[T](v T) {
|
||||
println(v)
|
||||
}
|
||||
|
||||
fn main() {
|
||||
f(none)
|
||||
}
|
Loading…
Reference in New Issue
Block a user