0 issues 1 contributor 4 branches 0 releases
Additions: 42 Deletions: 26 View patch
1 }
2 }
3 }
4+ if mut branch.cond is ast.IfGuardExpr {
5+ sym := c.table.sym(branch.cond.expr_type)
6+ if sym.kind == .multi_return {
7+ mr_info := sym.info as ast.MultiReturn
8+ if branch.cond.vars.len != mr_info.types.len {
9+ c.error('if guard expects $mr_info.types.len variables, but got $branch.cond.vars.len',
10+ branch.pos)
11+ continue
12+ } else {
13+ for vi, var in branch.cond.vars {
14+ branch.scope.update_var_type(var.name, mr_info.types[vi])
15+ }
16+ }
17+ }
18+ }
19 if node.is_comptime { // Skip checking if needed
20 // smartcast field type on comptime if
21 mut comptime_field_name := ''
22 branch.pos)
23 }
24 }
25- if mut branch.cond is ast.IfGuardExpr {
26- sym := c.table.sym(branch.cond.expr_type)
27- if sym.kind == .multi_return {
28- mr_info := sym.info as ast.MultiReturn
29- if branch.cond.vars.len != mr_info.types.len {
30- c.error('if guard expects $mr_info.types.len variables, but got $branch.cond.vars.len',
31- branch.pos)
32- } else {
33- for vi, var in branch.cond.vars {
34- branch.scope.update_var_type(var.name, mr_info.types[vi])
35- }
36- }
37- }
38- }
39 // Also check for returns inside a comp.if's statements, even if its contents aren't parsed
40 if has_return := c.has_return(branch.stmts) {
41 if has_return {
42
1-vlib/v/checker/tests/if_guard_variables_err.vv:6:2: error: if guard expects 3 variables, but got 1
2- 4 |
3- 5 | fn main() {
4- 6 | if r1 := create() {
5+vlib/v/checker/tests/if_guard_variables_err.vv:10:2: error: if guard expects 3 variables, but got 1
6+ 8 |
7+ 9 | fn main() {
8+ 10 | if r1 := create() {
9 | ~~~~~~~~~~~~~~~~~
10- 7 | println(r1)
11- 8 | }
12-vlib/v/checker/tests/if_guard_variables_err.vv:10:2: error: if guard expects 3 variables, but got 4
13- 8 | }
14- 9 |
15- 10 | if r1, r2, r3, r4 := create() {
16- | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
17 11 | println(r1)
18- 12 | println(r2)
19+ 12 | }
20+vlib/v/checker/tests/if_guard_variables_err.vv:14:2: error: if guard expects 3 variables, but got 4
21+ 12 | }
22+ 13 |
23+ 14 | if r1, r2, r3, r4 := create() {
24+ | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
25+ 15 | println(r1)
26+ 16 | println(r2)
27+vlib/v/checker/tests/if_guard_variables_err.vv:21:2: error: if guard expects 2 variables, but got 1
28+ 19 | }
29+ 20 |
30+ 21 | if x := maybe() {
31+ | ~~~~~~~~~~~~~~~
32+ 22 | println('$x')
33+ 23 | }
34
1 return 5, 'aa', true
2 }
3
4+fn maybe() ?(int, int) {
5+ return 1, 2
6+}
7+
8 fn main() {
9 if r1 := create() {
10 println(r1)
11 println(r3)
12 println(r4)
13 }
14+
15+ if x := maybe() {
16+ println('$x')
17+ }
18 }
19