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:
parent
634796ae42
commit
3091f31019
@ -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())
|
||||
|
6
vlib/v/checker/tests/optional_in_dump_err.out
Normal file
6
vlib/v/checker/tests/optional_in_dump_err.out
Normal 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 | }
|
11
vlib/v/checker/tests/optional_in_dump_err.vv
Normal file
11
vlib/v/checker/tests/optional_in_dump_err.vv
Normal file
@ -0,0 +1,11 @@
|
||||
struct AStruct {
|
||||
field1 int
|
||||
}
|
||||
|
||||
fn create() ?AStruct {
|
||||
return AStruct{123}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
dump(create())
|
||||
}
|
Loading…
Reference in New Issue
Block a user