Skip to content

Commit

Permalink
cgen: fix match with mut cond variable (#22207)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyi98 authored Sep 13, 2024
1 parent 6eae77b commit 4572c64
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion vlib/v/gen/c/match.v
Original file line number Diff line number Diff line change
Expand Up @@ -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(')')
}
Expand Down
10 changes: 10 additions & 0 deletions vlib/v/tests/conditions/matches/match_with_mut_cond_var_test.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
fn test_match_with_mut_cond_var() {
mut aaa := []string{}
for mut ccc in aaa {
match ccc {
'/' {}
else {}
}
}
assert true
}

0 comments on commit 4572c64

Please sign in to comment.