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:
parent
729f9c3391
commit
e31d892598
@ -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)
|
||||||
|
15
vlib/compiler/tests/repeated_multiret_values_test.v
Normal file
15
vlib/compiler/tests/repeated_multiret_values_test.v
Normal 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
|
||||||
|
}
|
27
vlib/compiler/tests/reusable_mut_multiret_values_test.v
Normal file
27
vlib/compiler/tests/reusable_mut_multiret_values_test.v
Normal 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
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user