checker: check error for fn decl with optional arguments (#14076)

yuyi 2022-04-19 02:22:31 +08:00 committed by Jef Roosens
parent 77593d6c68
commit 898167f986
Signed by: Jef Roosens
GPG Key ID: B75D4F293C7052DB
3 changed files with 15 additions and 0 deletions

View File

@ -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_ {

View 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 | }

View File

@ -0,0 +1,7 @@
fn optional_arg(x ?int) {
println('int type: $x')
}
fn main() {
optional_arg(1)
}