mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker, cgen: fix for mut i in arr { i = i * i }
(#17020)
This commit is contained in:
parent
1cad788779
commit
6a9688ce9d
@ -69,7 +69,7 @@ fn (mut c Checker) infix_expr(mut node ast.InfixExpr) ast.Type {
|
||||
c.error('invalid number of operand for `${node.op}`. Only one allowed on each side.',
|
||||
left_right_pos)
|
||||
}
|
||||
if left_type.is_any_kind_of_pointer()
|
||||
if left_type.is_any_kind_of_pointer() && !node.left.is_auto_deref_var()
|
||||
&& node.op in [.plus, .minus, .mul, .div, .mod, .xor, .amp, .pipe] {
|
||||
if !c.pref.translated && ((right_type.is_any_kind_of_pointer() && node.op != .minus)
|
||||
|| (!right_type.is_any_kind_of_pointer() && node.op !in [.plus, .minus])) {
|
||||
|
@ -966,7 +966,12 @@ fn (mut g Gen) gen_plain_infix_expr(node ast.InfixExpr) {
|
||||
}
|
||||
g.expr(node.left)
|
||||
g.write(' ${node.op.str()} ')
|
||||
g.expr_with_cast(node.right, node.right_type, node.left_type)
|
||||
if node.right_type.is_ptr() && node.right.is_auto_deref_var() {
|
||||
g.write('*')
|
||||
g.expr(node.right)
|
||||
} else {
|
||||
g.expr_with_cast(node.right, node.right_type, node.left_type)
|
||||
}
|
||||
}
|
||||
|
||||
fn (mut g Gen) op_arg(expr ast.Expr, expected ast.Type, got ast.Type) {
|
||||
|
8
vlib/v/tests/for_in_mut_array_with_mul_test.v
Normal file
8
vlib/v/tests/for_in_mut_array_with_mul_test.v
Normal file
@ -0,0 +1,8 @@
|
||||
fn test_for_in_mut_array_with_mul() {
|
||||
mut ints_a := [1, 2]
|
||||
for mut i in ints_a {
|
||||
i = i * i
|
||||
}
|
||||
print('${ints_a}')
|
||||
assert ints_a == [1, 4]
|
||||
}
|
Loading…
Reference in New Issue
Block a user