checker: fix multi assignment for multiple fns (#5716)
parent
d2d4ea42ce
commit
68e01d87be
|
@ -1536,7 +1536,9 @@ pub fn (mut c Checker) assign_stmt(mut assign_stmt ast.AssignStmt) {
|
|||
}
|
||||
if assign_stmt.right_types.len < assign_stmt.left.len { // first type or multi return types added above
|
||||
right_type := c.expr(assign_stmt.right[i])
|
||||
assign_stmt.right_types << c.check_expr_opt_call(assign_stmt.right[i], right_type)
|
||||
if assign_stmt.right_types.len == i {
|
||||
assign_stmt.right_types << c.check_expr_opt_call(assign_stmt.right[i], right_type)
|
||||
}
|
||||
}
|
||||
right := if i < assign_stmt.right.len { assign_stmt.right[i] } else { assign_stmt.right[0] }
|
||||
right_type := assign_stmt.right_types[i]
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
fn test() int {
|
||||
return 10
|
||||
}
|
||||
|
||||
fn test1() int {
|
||||
return 11
|
||||
}
|
||||
|
||||
fn test_fn_assignment_var() {
|
||||
mut a := 0
|
||||
mut b := 0
|
||||
a , b = test(), test1()
|
||||
|
||||
assert a == 10
|
||||
assert b == 11
|
||||
|
||||
a, b = test(), test()
|
||||
assert a == 10
|
||||
assert b == 10
|
||||
|
||||
a, b = test(), 12
|
||||
|
||||
assert a == 10
|
||||
assert b == 12
|
||||
|
||||
a, b = 12, test()
|
||||
|
||||
assert a == 12
|
||||
assert b == 10
|
||||
}
|
||||
|
||||
fn test_fn_assignment_array() {
|
||||
mut a := [0, 1]
|
||||
|
||||
a[0], a[1] = test(), test1()
|
||||
|
||||
assert a[0] == 10
|
||||
assert a[1] == 11
|
||||
|
||||
a[0], a[1] = test() , test()
|
||||
|
||||
assert a[0] == 10
|
||||
assert a[1] == 10
|
||||
|
||||
a[0], a[1] = test(), 12
|
||||
|
||||
assert a[0] == 10
|
||||
assert a[1] == 12
|
||||
|
||||
a[0], a[1] = 12 , test()
|
||||
assert a[0] == 12
|
||||
assert a[1] == 10
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue