checker: check for optional argument in dump() (#14316)

yuyi 2022-05-06 02:15:22 +08:00 committed by Jef Roosens
parent 3f588a1c4e
commit 055af924d9
Signed by: Jef Roosens
GPG Key ID: B75D4F293C7052DB
3 changed files with 18 additions and 0 deletions

View File

@ -2670,6 +2670,7 @@ pub fn (mut c Checker) expr(node_ ast.Expr) ast.Type {
} }
ast.DumpExpr { ast.DumpExpr {
node.expr_type = c.expr(node.expr) node.expr_type = c.expr(node.expr)
c.check_expr_opt_call(node.expr, node.expr_type)
etidx := node.expr_type.idx() etidx := node.expr_type.idx()
if etidx == ast.void_type_idx { if etidx == ast.void_type_idx {
c.error('dump expression can not be void', node.expr.pos()) c.error('dump expression can not be void', node.expr.pos())

View File

@ -0,0 +1,6 @@
vlib/v/checker/tests/optional_in_dump_err.vv:10:7: error: create() returns an option, so it should have either an `or {}` block, or `?` at the end
8 |
9 | fn main() {
10 | dump(create())
| ~~~~~~~~
11 | }

View File

@ -0,0 +1,11 @@
struct AStruct {
field1 int
}
fn create() ?AStruct {
return AStruct{123}
}
fn main() {
dump(create())
}