diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index abd604dc2a..b0f2e4fe4e 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -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()) diff --git a/vlib/v/checker/tests/optional_in_dump_err.out b/vlib/v/checker/tests/optional_in_dump_err.out new file mode 100644 index 0000000000..0d63178d4a --- /dev/null +++ b/vlib/v/checker/tests/optional_in_dump_err.out @@ -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 | } diff --git a/vlib/v/checker/tests/optional_in_dump_err.vv b/vlib/v/checker/tests/optional_in_dump_err.vv new file mode 100644 index 0000000000..5554ce417a --- /dev/null +++ b/vlib/v/checker/tests/optional_in_dump_err.vv @@ -0,0 +1,11 @@ +struct AStruct { + field1 int +} + +fn create() ?AStruct { + return AStruct{123} +} + +fn main() { + dump(create()) +}