cgen: fix infix ops, for cross assignments of types with overloaded operators (#12192)
parent
814b4ebb4c
commit
27cd21e459
vlib/v
gen/c
tests
|
@ -3269,9 +3269,22 @@ fn (mut g Gen) gen_cross_tmp_variable(left []ast.Expr, val ast.Expr) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ast.InfixExpr {
|
ast.InfixExpr {
|
||||||
g.gen_cross_tmp_variable(left, val.left)
|
sym := g.table.get_type_symbol(val.left_type)
|
||||||
g.write(val.op.str())
|
if _ := g.table.type_find_method(sym, val.op.str()) {
|
||||||
g.gen_cross_tmp_variable(left, val.right)
|
left_styp := g.typ(val.left_type.set_nr_muls(0))
|
||||||
|
g.write(left_styp)
|
||||||
|
g.write('_')
|
||||||
|
g.write(util.replace_op(val.op.str()))
|
||||||
|
g.write('(')
|
||||||
|
g.gen_cross_tmp_variable(left, val.left)
|
||||||
|
g.write(', ')
|
||||||
|
g.gen_cross_tmp_variable(left, val.right)
|
||||||
|
g.write(')')
|
||||||
|
} else {
|
||||||
|
g.gen_cross_tmp_variable(left, val.left)
|
||||||
|
g.write(val.op.str())
|
||||||
|
g.gen_cross_tmp_variable(left, val.right)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ast.PrefixExpr {
|
ast.PrefixExpr {
|
||||||
g.write(val.op.str())
|
g.write(val.op.str())
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import math.big
|
||||||
|
|
||||||
// Test cross assign of array elements
|
// Test cross assign of array elements
|
||||||
fn test_cross_assign_of_array() {
|
fn test_cross_assign_of_array() {
|
||||||
mut a := [0, 1]
|
mut a := [0, 1]
|
||||||
|
@ -157,3 +159,12 @@ fn test_cross_assign_of_complex_types() {
|
||||||
assert x.a == 2
|
assert x.a == 2
|
||||||
assert x.b == -1
|
assert x.b == -1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn test_cross_assign_of_big_int() {
|
||||||
|
mut a := big.zero_int
|
||||||
|
mut b := big.one_int
|
||||||
|
|
||||||
|
a, b = a + b, a
|
||||||
|
println(a)
|
||||||
|
assert a == big.one_int
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue