diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index bb3596a97a..2b8e80e134 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -2626,22 +2626,25 @@ pub fn (mut c Checker) assign_stmt(mut assign_stmt ast.AssignStmt) { right_first := assign_stmt.right[0] mut right_len := assign_stmt.right.len mut right_type0 := table.void_type - for right in assign_stmt.right { + for i, right in assign_stmt.right { if right is ast.CallExpr || right is ast.IfExpr || right is ast.LockExpr || right is ast.MatchExpr { - right_type0 = c.expr(right) - assign_stmt.right_types = [ - c.check_expr_opt_call(right, right_type0), - ] - right_type_sym0 := c.table.get_type_symbol(right_type0) - if right_type_sym0.kind == .multi_return { + right_type := c.expr(right) + if i == 0 { + right_type0 = right_type + assign_stmt.right_types = [ + c.check_expr_opt_call(right, right_type0), + ] + } + right_type_sym := c.table.get_type_symbol(right_type) + if right_type_sym.kind == .multi_return { if assign_stmt.right.len > 1 { - c.error('cannot use multi-value $right_type_sym0.name in signle-value context', + c.error('cannot use multi-value $right_type_sym.name in single-value context', right.position()) } - assign_stmt.right_types = right_type_sym0.mr_info().types + assign_stmt.right_types = right_type_sym.mr_info().types right_len = assign_stmt.right_types.len - } else if right_type0 == table.void_type { + } else if right_type == table.void_type { right_len = 0 } } diff --git a/vlib/v/checker/tests/assign_multi_mismatch.out b/vlib/v/checker/tests/assign_multi_mismatch.out index 23c1ef9a6a..ded3db72c5 100644 --- a/vlib/v/checker/tests/assign_multi_mismatch.out +++ b/vlib/v/checker/tests/assign_multi_mismatch.out @@ -12,42 +12,42 @@ vlib/v/checker/tests/assign_multi_mismatch.vv:6:3: error: assignment mismatch: 1 | ~~ 7 | _, _ := f() 8 | _, _ := 0, f() -vlib/v/checker/tests/assign_multi_mismatch.vv:8:12: error: cannot use multi-value (int, int) in signle-value context +vlib/v/checker/tests/assign_multi_mismatch.vv:8:12: error: cannot use multi-value (int, int) in single-value context 6 | _ := f() 7 | _, _ := f() 8 | _, _ := 0, f() | ~~~ 9 | _, _ := f(), 0 10 | _, _, _ := 0, f() -vlib/v/checker/tests/assign_multi_mismatch.vv:9:9: error: cannot use multi-value (int, int) in signle-value context +vlib/v/checker/tests/assign_multi_mismatch.vv:9:9: error: cannot use multi-value (int, int) in single-value context 7 | _, _ := f() 8 | _, _ := 0, f() 9 | _, _ := f(), 0 | ~~~ 10 | _, _, _ := 0, f() 11 | _, _, _ := f(), 0 -vlib/v/checker/tests/assign_multi_mismatch.vv:10:15: error: cannot use multi-value (int, int) in signle-value context +vlib/v/checker/tests/assign_multi_mismatch.vv:10:15: error: cannot use multi-value (int, int) in single-value context 8 | _, _ := 0, f() 9 | _, _ := f(), 0 10 | _, _, _ := 0, f() | ~~~ 11 | _, _, _ := f(), 0 12 | _, _ := f(), f() -vlib/v/checker/tests/assign_multi_mismatch.vv:11:12: error: cannot use multi-value (int, int) in signle-value context +vlib/v/checker/tests/assign_multi_mismatch.vv:11:12: error: cannot use multi-value (int, int) in single-value context 9 | _, _ := f(), 0 10 | _, _, _ := 0, f() 11 | _, _, _ := f(), 0 | ~~~ 12 | _, _ := f(), f() 13 | _, _, _, _ := f(), f() -vlib/v/checker/tests/assign_multi_mismatch.vv:12:9: error: cannot use multi-value (int, int) in signle-value context +vlib/v/checker/tests/assign_multi_mismatch.vv:12:9: error: cannot use multi-value (int, int) in single-value context 10 | _, _, _ := 0, f() 11 | _, _, _ := f(), 0 12 | _, _ := f(), f() | ~~~ 13 | _, _, _, _ := f(), f() 14 | -vlib/v/checker/tests/assign_multi_mismatch.vv:13:15: error: cannot use multi-value (int, int) in signle-value context +vlib/v/checker/tests/assign_multi_mismatch.vv:13:15: error: cannot use multi-value (int, int) in single-value context 11 | _, _, _ := f(), 0 12 | _, _ := f(), f() 13 | _, _, _, _ := f(), f() @@ -61,7 +61,7 @@ vlib/v/checker/tests/assign_multi_mismatch.vv:19:3: error: assignment mismatch: | ~~ 20 | 1 { f() } 21 | else { f() } -vlib/v/checker/tests/assign_multi_mismatch.vv:23:12: error: cannot use multi-value (int, int) in signle-value context +vlib/v/checker/tests/assign_multi_mismatch.vv:23:12: error: cannot use multi-value (int, int) in single-value context 21 | else { f() } 22 | } 23 | _, _ := 0, match 4 { @@ -74,7 +74,7 @@ vlib/v/checker/tests/assign_multi_mismatch.vv:29:3: error: assignment mismatch: 29 | _ := if true { f() } else { f() } | ~~ 30 | _, _ := 0, if true { f() } else { f() } -vlib/v/checker/tests/assign_multi_mismatch.vv:30:12: error: cannot use multi-value (int, int) in signle-value context +vlib/v/checker/tests/assign_multi_mismatch.vv:30:12: error: cannot use multi-value (int, int) in single-value context 28 | _, _ := 0, if true { 0 } else { 1 } 29 | _ := if true { f() } else { f() } 30 | _, _ := 0, if true { f() } else { f() } diff --git a/vlib/v/tests/complex_assign_test.v b/vlib/v/tests/complex_assign_test.v index dd80430468..875f39fa34 100644 --- a/vlib/v/tests/complex_assign_test.v +++ b/vlib/v/tests/complex_assign_test.v @@ -104,3 +104,20 @@ fn test_assign_multi_expr() { assert s.value == 555 assert s.name == 'initial' } + +fn test_issue_9330() { + arr := "0.1".split('.') + a0, a1 := arr[0], arr[1].int() + assert a0 == '0' + assert a1 == 1 + b0, b1 := arr[0].int(), arr[1] + assert b0 == 0 + assert b1 == '1' + c0, c1 := arr[0], arr[1] + assert c0 == '0' + assert c1 == '1' + d0, d1 := arr[0].int(), arr[1].f64() + assert d0 == 0 + assert d1 == 1.0 + +}