1
0
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:
yuyi 2022-04-19 02:22:31 +08:00 committed by GitHub
parent d0a11f50ca
commit 7ef64bde50
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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)
}