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

cgen: fix cross assign with generic fn call (#18050)

This commit is contained in:
yuyi 2023-04-27 01:41:20 +08:00 committed by GitHub
parent 28f85371b1
commit e1e5076d94
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -985,7 +985,10 @@ fn (mut g Gen) gen_cross_tmp_variable(left []ast.Expr, val ast.Expr) {
g.write(')')
}
ast.CallExpr {
fn_name := val.name.replace('.', '__')
mut fn_name := val.name.replace('.', '__')
if val.concrete_types.len > 0 {
fn_name = g.generic_fn_name(val.concrete_types, fn_name)
}
g.write('${fn_name}(')
for i, arg in val.args {
g.gen_cross_tmp_variable(left, arg.expr)

View File

@ -0,0 +1,10 @@
import math
fn test_cross_assign_with_generic_fn_call() {
mut x := -1
mut y := -2
x, y = y, math.abs(x)
println('${x} | ${y}')
assert x == -2
assert y == 1
}