From 0eee012ae9165b0523ed0ede7df4e029b4b4d107 Mon Sep 17 00:00:00 2001 From: crthpl <56052645+crthpl@users.noreply.github.com> Date: Sat, 12 Feb 2022 01:55:25 -0800 Subject: [PATCH] cgen: fix `x in shared_map` (#13442) --- vlib/v/gen/c/infix_expr.v | 5 ++++- vlib/v/tests/shared_map_test.v | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/vlib/v/gen/c/infix_expr.v b/vlib/v/gen/c/infix_expr.v index b383640efe..752aa9e470 100644 --- a/vlib/v/gen/c/infix_expr.v +++ b/vlib/v/gen/c/infix_expr.v @@ -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) diff --git a/vlib/v/tests/shared_map_test.v b/vlib/v/tests/shared_map_test.v index 187274e257..d6442a0a9f 100644 --- a/vlib/v/tests/shared_map_test.v +++ b/vlib/v/tests/shared_map_test.v @@ -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 + } +}