checker: check error for fn decl with optional arguments (#14076)
parent
77593d6c68
commit
898167f986
|
@ -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',
|
c.error('invalid use of reserved type `$param.name` as a parameter name',
|
||||||
param.pos)
|
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]`
|
if !param.typ.is_ptr() { // value parameter, i.e. on stack - check for `[heap]`
|
||||||
arg_typ_sym := c.table.sym(param.typ)
|
arg_typ_sym := c.table.sym(param.typ)
|
||||||
if arg_typ_sym.kind == .struct_ {
|
if arg_typ_sym.kind == .struct_ {
|
||||||
|
|
|
@ -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 | }
|
|
@ -0,0 +1,7 @@
|
||||||
|
fn optional_arg(x ?int) {
|
||||||
|
println('int type: $x')
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
optional_arg(1)
|
||||||
|
}
|
Loading…
Reference in New Issue