v.checker: fix panic for `a, b, c = fn_returning_several_maps()`
parent
0916806350
commit
02e4aa0f0e
|
@ -4019,10 +4019,17 @@ pub fn (mut c Checker) assign_stmt(mut node ast.AssignStmt) {
|
|||
// `map = {}`
|
||||
if left_type != 0 {
|
||||
sym := c.table.get_type_symbol(left_type)
|
||||
if sym.kind == .map && node.right[i] is ast.StructInit {
|
||||
c.warn('assigning a struct literal to a map is deprecated - use `map{}` instead',
|
||||
node.right[i].position())
|
||||
node.right[i] = ast.MapInit{}
|
||||
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',
|
||||
node.right[i].position())
|
||||
node.right[i] = ast.MapInit{}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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