mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: fix mut map with relation op in fn (#5642)
This commit is contained in:
parent
9e949622d3
commit
a2395ff3e8
@ -313,3 +313,35 @@ fn test_map_in_mut() {
|
||||
map_in_mut(mut m)
|
||||
assert m['one'] == 2
|
||||
}
|
||||
|
||||
fn mut_map_with_relation_op_in_fn(mut m map[string]int) {
|
||||
if m['one'] == 1 {
|
||||
m['three'] = 3
|
||||
}
|
||||
if m['two'] != 1 {
|
||||
m['four'] = 4
|
||||
}
|
||||
if m['one'] > 0 {
|
||||
m['five'] = 5
|
||||
}
|
||||
if m['one'] < 2 {
|
||||
m['six'] = 6
|
||||
}
|
||||
if m['two'] >= 2 {
|
||||
m['seven'] = 7
|
||||
}
|
||||
if m['two'] <= 2 {
|
||||
m['eight'] = 8
|
||||
}
|
||||
}
|
||||
|
||||
fn test_mut_map_with_relation_op_in_fn() {
|
||||
mut m := {'one':1, 'two':2}
|
||||
mut_map_with_relation_op_in_fn(mut m)
|
||||
assert 'three' in m
|
||||
assert 'four' in m
|
||||
assert 'five' in m
|
||||
assert 'six' in m
|
||||
assert 'seven' in m
|
||||
assert 'eight' in m
|
||||
}
|
||||
|
@ -2360,6 +2360,9 @@ fn (mut g Gen) index_expr(node ast.IndexExpr) {
|
||||
} else {
|
||||
zero := g.type_default(info.value_type)
|
||||
g.write('(*($elem_type_str*)map_get(')
|
||||
if node.left_type.is_ptr() {
|
||||
g.write('*')
|
||||
}
|
||||
g.expr(node.left)
|
||||
g.write(', ')
|
||||
g.expr(node.index)
|
||||
|
Loading…
Reference in New Issue
Block a user