cgen: fix setting map elements' fields (#6699)
parent
b59c5fd82b
commit
a2a0765eff
|
@ -750,27 +750,21 @@ fn (mut cfg DocConfig) generate_docs_from_file() {
|
||||||
readme_contents := cfg.get_readme(dirpath)
|
readme_contents := cfg.get_readme(dirpath)
|
||||||
dcs.head.comment = readme_contents
|
dcs.head.comment = readme_contents
|
||||||
}
|
}
|
||||||
mut new_contents := map[string]doc.DocNode{}
|
|
||||||
if cfg.pub_only {
|
if cfg.pub_only {
|
||||||
for name, oc in dcs.contents {
|
for name, dc in dcs.contents {
|
||||||
mut c := oc
|
dcs.contents[name].content = dc.content.all_after('pub ')
|
||||||
c.content = c.content.all_after('pub ')
|
for i, cc in dc.children {
|
||||||
for i, cc in c.children {
|
dcs.contents[name].children[i].content = cc.content.all_after('pub ')
|
||||||
c.children[i].content = cc.content.all_after('pub ')
|
|
||||||
}
|
}
|
||||||
new_contents[name] = c
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !cfg.is_multi && cfg.symbol_name.len > 0 {
|
if !cfg.is_multi && cfg.symbol_name.len > 0 {
|
||||||
if cfg.symbol_name in dcs.contents {
|
if cfg.symbol_name in dcs.contents {
|
||||||
new_contents[cfg.symbol_name] = dcs.contents[cfg.symbol_name]
|
for _, c in dcs.contents[cfg.symbol_name].children {
|
||||||
children := dcs.contents[cfg.symbol_name].children
|
dcs.contents[c.name] = c
|
||||||
for _, c in children {
|
|
||||||
new_contents[c.name] = c
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dcs.contents = new_contents
|
|
||||||
}
|
}
|
||||||
cfg.docs << dcs
|
cfg.docs << dcs
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
// import time
|
// import time
|
||||||
|
|
||||||
struct User {
|
struct User {
|
||||||
|
mut:
|
||||||
name string
|
name string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,6 +55,10 @@ fn test_map() {
|
||||||
a.users['Bob'] = User{'Bob'}
|
a.users['Bob'] = User{'Bob'}
|
||||||
q := a.users['Bob']
|
q := a.users['Bob']
|
||||||
assert q.name == 'Bob'
|
assert q.name == 'Bob'
|
||||||
|
// test struct field change
|
||||||
|
a.users['Bob'].name = 'bob'
|
||||||
|
q2 := a.users['Bob']
|
||||||
|
assert q2.name == 'bob'
|
||||||
a.m['one'] = 1
|
a.m['one'] = 1
|
||||||
a.set('two', 2)
|
a.set('two', 2)
|
||||||
assert a.m['one'] == 1
|
assert a.m['one'] == 1
|
||||||
|
@ -308,19 +313,19 @@ fn mut_map_with_relation_op_in_fn(mut m map[string]int) {
|
||||||
m['three'] = 3
|
m['three'] = 3
|
||||||
}
|
}
|
||||||
if m['two'] != 1 {
|
if m['two'] != 1 {
|
||||||
m['four'] = 4
|
m['four'] = 4
|
||||||
}
|
}
|
||||||
if m['one'] > 0 {
|
if m['one'] > 0 {
|
||||||
m['five'] = 5
|
m['five'] = 5
|
||||||
}
|
}
|
||||||
if m['one'] < 2 {
|
if m['one'] < 2 {
|
||||||
m['six'] = 6
|
m['six'] = 6
|
||||||
}
|
}
|
||||||
if m['two'] >= 2 {
|
if m['two'] >= 2 {
|
||||||
m['seven'] = 7
|
m['seven'] = 7
|
||||||
}
|
}
|
||||||
if m['two'] <= 2 {
|
if m['two'] <= 2 {
|
||||||
m['eight'] = 8
|
m['eight'] = 8
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3491,7 +3491,7 @@ fn (mut g Gen) index_expr(node ast.IndexExpr) {
|
||||||
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)
|
||||||
elem_typ := g.table.get_type_symbol(info.value_type)
|
elem_typ := g.table.get_type_symbol(info.value_type)
|
||||||
if g.is_assign_lhs && !g.is_array_set {
|
if g.is_assign_lhs && !g.is_array_set && elem_typ.kind != .struct_ {
|
||||||
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 {
|
||||||
|
@ -3505,7 +3505,8 @@ fn (mut g Gen) index_expr(node ast.IndexExpr) {
|
||||||
} else {
|
} else {
|
||||||
g.write(', &($elem_type_str[]) { ')
|
g.write(', &($elem_type_str[]) { ')
|
||||||
}
|
}
|
||||||
} else if g.inside_map_postfix || g.inside_map_infix {
|
} else if (g.inside_map_postfix || g.inside_map_infix) ||
|
||||||
|
(g.is_assign_lhs && !g.is_array_set && elem_typ.kind == .struct_) {
|
||||||
zero := g.type_default(info.value_type)
|
zero := g.type_default(info.value_type)
|
||||||
g.write('(*($elem_type_str*)map_get_and_set(')
|
g.write('(*($elem_type_str*)map_get_and_set(')
|
||||||
if !left_is_ptr {
|
if !left_is_ptr {
|
||||||
|
|
Loading…
Reference in New Issue