From fe368a1e949185b37faeca435170fa728c65b4c6 Mon Sep 17 00:00:00 2001 From: yuyi Date: Fri, 13 Sep 2024 10:15:31 +0800 Subject: [PATCH] cgen: fix match with mut cond variable --- 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 44fb27e737c3a9..b79050b8a5da08 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 00000000000000..ba88dbdafebc19 --- /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 +}