1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

cgen: fix 'for in mut val' with 'if val in' (#13263)

This commit is contained in:
yuyi 2022-01-24 23:08:21 +08:00 committed by GitHub
parent 7199528a27
commit 509a8fcaf1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 0 deletions

View File

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

View File

@ -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
}