mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: check error for fn decl with optional arguments (#14076)
This commit is contained in:
parent
d0a11f50ca
commit
7ef64bde50
@ -181,6 +181,9 @@ fn (mut c Checker) fn_decl(mut node ast.FnDecl) {
|
||||
c.error('invalid use of reserved type `$param.name` as a parameter name',
|
||||
param.pos)
|
||||
}
|
||||
if param.typ.has_flag(.optional) {
|
||||
c.error('optional type argument is not supported currently', param.type_pos)
|
||||
}
|
||||
if !param.typ.is_ptr() { // value parameter, i.e. on stack - check for `[heap]`
|
||||
arg_typ_sym := c.table.sym(param.typ)
|
||||
if arg_typ_sym.kind == .struct_ {
|
||||
|
5
vlib/v/checker/tests/fn_arg_of_optional_err.out
Normal file
5
vlib/v/checker/tests/fn_arg_of_optional_err.out
Normal file
@ -0,0 +1,5 @@
|
||||
vlib/v/checker/tests/fn_arg_of_optional_err.vv:1:19: error: optional type argument is not supported currently
|
||||
1 | fn optional_arg(x ?int) {
|
||||
| ^
|
||||
2 | println('int type: $x')
|
||||
3 | }
|
7
vlib/v/checker/tests/fn_arg_of_optional_err.vv
Normal file
7
vlib/v/checker/tests/fn_arg_of_optional_err.vv
Normal file
@ -0,0 +1,7 @@
|
||||
fn optional_arg(x ?int) {
|
||||
println('int type: $x')
|
||||
}
|
||||
|
||||
fn main() {
|
||||
optional_arg(1)
|
||||
}
|
Loading…
Reference in New Issue
Block a user