From 4572c64759afe994afb9c1b3a2eedd5ddfe49a21 Mon Sep 17 00:00:00 2001 From: yuyi Date: Fri, 13 Sep 2024 13:20:06 +0800 Subject: [PATCH] cgen: fix match with mut cond variable (#22207) --- vlib/v/gen/c/match.v | 3 ++- .../conditions/matches/match_with_mut_cond_var_test.v | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 vlib/v/tests/conditions/matches/match_with_mut_cond_var_test.v diff --git a/vlib/v/gen/c/match.v b/vlib/v/gen/c/match.v index 44fb27e737..b79050b8a5 100644 --- a/vlib/v/gen/c/match.v +++ b/vlib/v/gen/c/match.v @@ -491,7 +491,8 @@ fn (mut g Gen) match_expr_classic(node ast.MatchExpr, is_expr bool, cond_var str g.write(')') } .string { - g.write('string__eq(${cond_var}, ') + ptr_str := if node.cond_type.is_ptr() { '*' } else { '' } + g.write('string__eq(${ptr_str}${cond_var}, ') g.expr(expr) g.write(')') } diff --git a/vlib/v/tests/conditions/matches/match_with_mut_cond_var_test.v b/vlib/v/tests/conditions/matches/match_with_mut_cond_var_test.v new file mode 100644 index 0000000000..ba88dbdafe --- /dev/null +++ b/vlib/v/tests/conditions/matches/match_with_mut_cond_var_test.v @@ -0,0 +1,10 @@ +fn test_match_with_mut_cond_var() { + mut aaa := []string{} + for mut ccc in aaa { + match ccc { + '/' {} + else {} + } + } + assert true +}