Skip to content

Commit

Permalink
cgen: fix 'for in mut val' with 'if val in' (#13263)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyi98 committed Jan 24, 2022
1 parent 7199528 commit 509a8fc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions vlib/v/gen/c/array.v
Expand Up @@ -710,6 +710,9 @@ fn (mut g Gen) gen_array_contains(typ ast.Type, left ast.Expr, right ast.Expr) {
g.write('->val')
}
g.write(', ')
if right.is_auto_deref_var() {
g.write('*')
}
g.expr(right)
g.write(')')
}
Expand Down
13 changes: 13 additions & 0 deletions vlib/v/tests/for_in_mut_val_with_if_val_in_test.v
@@ -0,0 +1,13 @@
fn test_for_in_mut_val_with_if_val_in() {
array := ['e']
mut splited := ['h', 'f', 's', 'e']
mut has_e := false

for mut s in splited {
if s in array {
println('Hello')
has_e = true
}
}
assert has_e
}

0 comments on commit 509a8fc

Please sign in to comment.