v.checker: fix panic for `a, b, c = fn_returning_several_maps()`
parent
0916806350
commit
02e4aa0f0e
|
@ -4019,13 +4019,20 @@ pub fn (mut c Checker) assign_stmt(mut node ast.AssignStmt) {
|
||||||
// `map = {}`
|
// `map = {}`
|
||||||
if left_type != 0 {
|
if left_type != 0 {
|
||||||
sym := c.table.get_type_symbol(left_type)
|
sym := c.table.get_type_symbol(left_type)
|
||||||
if sym.kind == .map && node.right[i] is ast.StructInit {
|
if sym.kind == .map {
|
||||||
|
if node.right.len <= i {
|
||||||
|
// `map_1, map_2, map_3 = f()`, where f returns (map[int]int, map[int]int, map[int]int)
|
||||||
|
// i.e. 3 left parts of the assignment, but just 1 right part
|
||||||
|
} else {
|
||||||
|
if node.right[i] is ast.StructInit {
|
||||||
c.warn('assigning a struct literal to a map is deprecated - use `map{}` instead',
|
c.warn('assigning a struct literal to a map is deprecated - use `map{}` instead',
|
||||||
node.right[i].position())
|
node.right[i].position())
|
||||||
node.right[i] = ast.MapInit{}
|
node.right[i] = ast.MapInit{}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if node.right_types.len < node.left.len { // first type or multi return types added above
|
if node.right_types.len < node.left.len { // first type or multi return types added above
|
||||||
old_inside_ref_lit := c.inside_ref_lit
|
old_inside_ref_lit := c.inside_ref_lit
|
||||||
if left is ast.Ident {
|
if left is ast.Ident {
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
fn many_maps() (map[int]int, map[int]int, map[int]int) {
|
||||||
|
return {
|
||||||
|
1: 2
|
||||||
|
}, {
|
||||||
|
3: 4
|
||||||
|
}, {
|
||||||
|
5: 1000
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_fn_returning_many_maps_at_the_same_time() {
|
||||||
|
mut a, mut b, mut c := {
|
||||||
|
0: 0
|
||||||
|
}, {
|
||||||
|
0: 0
|
||||||
|
}, {
|
||||||
|
0: 0
|
||||||
|
}
|
||||||
|
a, b, c = many_maps()
|
||||||
|
dump(a)
|
||||||
|
dump(b)
|
||||||
|
dump(c)
|
||||||
|
assert a == {
|
||||||
|
1: 2
|
||||||
|
}
|
||||||
|
assert b == {
|
||||||
|
3: 4
|
||||||
|
}
|
||||||
|
assert c == {
|
||||||
|
5: 1000
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue