1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

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

This commit is contained in:
yuyi 2022-05-06 02:15:22 +08:00 committed by GitHub
parent 634796ae42
commit 3091f31019
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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 {
node.expr_type = c.expr(node.expr)
c.check_expr_opt_call(node.expr, node.expr_type)
etidx := node.expr_type.idx()
if etidx == ast.void_type_idx {
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())
}