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

make _V_mret_ unique by putting p.token_idx in it

This commit is contained in:
bogen85 2019-11-29 02:11:53 -06:00 committed by Alexander Medvednikov
parent 729f9c3391
commit e31d892598
3 changed files with 74 additions and 32 deletions

View File

@ -1471,7 +1471,7 @@ fn (p mut Parser) var_decl() {
if is_decl_assign && var_names.len == 1 && var_names[0] == '_' { if is_decl_assign && var_names.len == 1 && var_names[0] == '_' {
p.error_with_token_index('use `=` instead of `:=`', var_token_idxs.last()) p.error_with_token_index('use `=` instead of `:=`', var_token_idxs.last())
} }
p.var_decl_name = if var_names.len > 1 { '_V_mret_'+var_names.join('_') } else { var_names[0] } p.var_decl_name = if var_names.len > 1 { '_V_mret_${p.token_idx}_'+var_names.join('_') } else { var_names[0] }
t := p.gen_var_decl(p.var_decl_name, is_static) t := p.gen_var_decl(p.var_decl_name, is_static)
if t == 'void' { if t == 'void' {
_, fn_name := p.is_expr_fn_call(p.token_idx-3) _, fn_name := p.is_expr_fn_call(p.token_idx-3)

View File

@ -0,0 +1,15 @@
// verify fix for #2913
fn some_multiret_fn(a int, b int) (int, int) {
return a+1, b+1
}
fn test_repeated_multiple_multiret() {
a, b := some_multiret_fn(1,2)
assert a == 2
assert b == 3
c, d := some_multiret_fn(3,4)
assert c == 4
assert d == 5
}

View File

@ -0,0 +1,27 @@
// verify fix for #2913
fn some_multiret_fn(a int, b int) (int, int) {
return a+1, b+1
}
fn test_reuse_multiple_multiret() {
mut c, mut d := some_multiret_fn(4,10)
mut a, mut b := some_multiret_fn(c,d)
assert a == c+1
assert b == d+1
for i in 1..10 {
c += i
d += i
a, b = some_multiret_fn(c,d)
assert a == c+1
assert b == d+1
c += i+1
d += i+1
a, b = some_multiret_fn(c,d)
assert a == c+1
assert b == d+1
}
}