cgen: fix match with mut cond variable (#22207)

This commit is contained in:
yuyi 2024-09-13 13:20:06 +08:00 committed by GitHub
parent 6eae77b61e
commit 4572c64759
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 1 deletions

View File

@ -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(')')
}

View File

@ -0,0 +1,10 @@
fn test_match_with_mut_cond_var() {
mut aaa := []string{}
for mut ccc in aaa {
match ccc {
'/' {}
else {}
}
}
assert true
}