cgen: fix `x in shared_map` (#13442)

pull/13449/head
crthpl 2022-02-12 01:55:25 -08:00 committed by GitHub
parent 37c151efe5
commit 0eee012ae9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 1 deletions

View File

@ -430,9 +430,12 @@ fn (mut g Gen) infix_expr_in_op(node ast.InfixExpr) {
g.expr(node.left)
}
g.write(', ')
if !right.typ.is_ptr() {
if !right.typ.is_ptr() || right.typ.has_flag(.shared_f) {
g.write('ADDR(map, ')
g.expr(node.right)
if right.typ.has_flag(.shared_f) {
g.write('->val')
}
g.write(')')
} else {
g.expr(node.right)

View File

@ -155,3 +155,17 @@ fn test_shared_map_iteration() {
assert n1 == 1
assert n2 == 1
}
fn test_shared_map_in() {
shared m := {
'qwe': 12.75
'rtz': -0.125
'k': 17
}
rlock m {
assert 'qwe' in m
assert 'rtz' in m
assert 'k' in m
assert 'zxc' !in m
}
}