Skip to content

Commit

Permalink
checker: check option propogation in multi return types
Browse files Browse the repository at this point in the history
  • Loading branch information
Delta456 committed Sep 25, 2023
1 parent 20bce37 commit f90c01d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions vlib/v/checker/assign.v
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ fn (mut c Checker) assign_stmt(mut node ast.AssignStmt) {
}
node.right_types = right_type_sym.mr_info().types
right_len = node.right_types.len
if mut right is ast.CallExpr {
if right.or_block.kind == .absent && right_type.has_flag(.option) {
c.error("cannot multi assign as Option isn't propagated", right.pos)
}
}
} else if right_type == ast.void_type {
right_len = 0
}
Expand Down
5 changes: 5 additions & 0 deletions vlib/v/checker/tests/multi_return_option_not_set_err.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
vlib/v/checker/tests/multi_return_option_not_set_err.vv:1:19: error: cannot multi assign as Option isn't propagated
1 | a, b := 'fdf:df:'.split_once(',')
| ~~~~~~~~~~~~~~~
2 | println(a)
3 | println(b)
3 changes: 3 additions & 0 deletions vlib/v/checker/tests/multi_return_option_not_set_err.vv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
a, b := 'fdf:df:'.split_once(',')
println(a)
println(b)

0 comments on commit f90c01d

Please sign in to comment.