mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: fix assignment to nested maps
This commit is contained in:
parent
f34352faf9
commit
4dd8796dba
@ -1710,7 +1710,7 @@ fn (g mut Gen) index_expr(node ast.IndexExpr) {
|
|||||||
} else if sym.kind == .map {
|
} else if sym.kind == .map {
|
||||||
info := sym.info as table.Map
|
info := sym.info as table.Map
|
||||||
elem_type_str := g.typ(info.value_type)
|
elem_type_str := g.typ(info.value_type)
|
||||||
if g.is_assign_lhs {
|
if g.is_assign_lhs && !g.is_array_set {
|
||||||
g.is_array_set = true
|
g.is_array_set = true
|
||||||
g.write('map_set(')
|
g.write('map_set(')
|
||||||
if !left_is_ptr {
|
if !left_is_ptr {
|
||||||
|
17
vlib/v/tests/nested_map_test.v
Normal file
17
vlib/v/tests/nested_map_test.v
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
fn test_nested_maps() {
|
||||||
|
x := map[string]map[string]int
|
||||||
|
x["a"] = map[string]int
|
||||||
|
assert x["a"]["b"] == 0
|
||||||
|
x["a"]["b"] = 5
|
||||||
|
assert x["a"]["b"] == 5
|
||||||
|
x["a"]["b"] = 7
|
||||||
|
assert x["a"]["b"] == 7
|
||||||
|
y := map[string]map[string]map[string]int
|
||||||
|
y["a"] = map[string]map[string]int
|
||||||
|
y["a"]["b"] = map[string]int
|
||||||
|
assert y["a"]["b"]["c"] == 0
|
||||||
|
y["a"]["b"]["c"] = 5
|
||||||
|
assert y["a"]["b"]["c"] == 5
|
||||||
|
y["a"]["b"]["c"] = 7
|
||||||
|
assert y["a"]["b"]["c"] == 7
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user