mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: fix multi return variable ignore in if guard (#17853)
This commit is contained in:
parent
01caecc284
commit
de34e15df7
@ -285,7 +285,7 @@ fn (mut g Gen) if_expr(node ast.IfExpr) {
|
|||||||
g.writeln(', !${var_name}.is_error) {')
|
g.writeln(', !${var_name}.is_error) {')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if short_opt || branch.cond.vars[0].name != '_' {
|
if short_opt || branch.cond.vars.len > 1 || branch.cond.vars[0].name != '_' {
|
||||||
base_type := g.base_type(branch.cond.expr_type)
|
base_type := g.base_type(branch.cond.expr_type)
|
||||||
if short_opt {
|
if short_opt {
|
||||||
cond_var_name := if branch.cond.vars[0].name == '_' {
|
cond_var_name := if branch.cond.vars[0].name == '_' {
|
||||||
@ -316,6 +316,9 @@ fn (mut g Gen) if_expr(node ast.IfExpr) {
|
|||||||
if sym.info is ast.MultiReturn {
|
if sym.info is ast.MultiReturn {
|
||||||
if sym.info.types.len == branch.cond.vars.len {
|
if sym.info.types.len == branch.cond.vars.len {
|
||||||
for vi, var in branch.cond.vars {
|
for vi, var in branch.cond.vars {
|
||||||
|
if var.name == '_' {
|
||||||
|
continue
|
||||||
|
}
|
||||||
var_typ := g.typ(sym.info.types[vi])
|
var_typ := g.typ(sym.info.types[vi])
|
||||||
left_var_name := c_name(var.name)
|
left_var_name := c_name(var.name)
|
||||||
if is_auto_heap {
|
if is_auto_heap {
|
||||||
|
32
vlib/v/gen/c/testdata/multi_return_ignored_if_guard.out
vendored
Normal file
32
vlib/v/gen/c/testdata/multi_return_ignored_if_guard.out
vendored
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
1
|
||||||
|
2
|
||||||
|
1
|
||||||
|
2
|
||||||
|
1
|
||||||
|
2
|
||||||
|
1
|
||||||
|
2
|
||||||
|
1
|
||||||
|
2
|
||||||
|
3
|
||||||
|
1
|
||||||
|
2
|
||||||
|
1
|
||||||
|
3
|
||||||
|
1
|
||||||
|
2
|
||||||
|
3
|
||||||
|
2
|
||||||
|
3
|
||||||
|
1
|
||||||
|
2
|
||||||
|
3
|
||||||
|
1
|
||||||
|
2
|
||||||
|
1
|
||||||
|
3
|
||||||
|
1
|
||||||
|
2
|
||||||
|
3
|
||||||
|
2
|
||||||
|
3
|
98
vlib/v/gen/c/testdata/multi_return_ignored_if_guard.vv
vendored
Normal file
98
vlib/v/gen/c/testdata/multi_return_ignored_if_guard.vv
vendored
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
fn f1() !(int, int) {
|
||||||
|
return 1, 2
|
||||||
|
}
|
||||||
|
|
||||||
|
fn f2() ?(int, int) {
|
||||||
|
return 1, 2
|
||||||
|
}
|
||||||
|
|
||||||
|
fn f3() !(int, int, int) {
|
||||||
|
return 1, 2, 3
|
||||||
|
}
|
||||||
|
|
||||||
|
fn f4() ?(int, int, int) {
|
||||||
|
return 1, 2, 3
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
if l, r := f1() {
|
||||||
|
println(l)
|
||||||
|
println(r)
|
||||||
|
}
|
||||||
|
if l, _ := f1() {
|
||||||
|
println(l)
|
||||||
|
}
|
||||||
|
if _, r := f1() {
|
||||||
|
println(r)
|
||||||
|
}
|
||||||
|
if _, _ := f1() {
|
||||||
|
}
|
||||||
|
if l, r := f2() {
|
||||||
|
println(l)
|
||||||
|
println(r)
|
||||||
|
}
|
||||||
|
if l, _ := f2() {
|
||||||
|
println(l)
|
||||||
|
}
|
||||||
|
if _, r := f2() {
|
||||||
|
println(r)
|
||||||
|
}
|
||||||
|
if _, _ := f2() {
|
||||||
|
}
|
||||||
|
if x, y, z := f3() {
|
||||||
|
println(x)
|
||||||
|
println(y)
|
||||||
|
println(z)
|
||||||
|
}
|
||||||
|
if x, y, _ := f3() {
|
||||||
|
println(x)
|
||||||
|
println(y)
|
||||||
|
}
|
||||||
|
if x, _, z := f3() {
|
||||||
|
println(x)
|
||||||
|
println(z)
|
||||||
|
}
|
||||||
|
if x, _, _ := f3() {
|
||||||
|
println(x)
|
||||||
|
}
|
||||||
|
if _, y, z := f3() {
|
||||||
|
println(y)
|
||||||
|
println(z)
|
||||||
|
}
|
||||||
|
if _, y, _ := f3() {
|
||||||
|
println(y)
|
||||||
|
}
|
||||||
|
if _, _, z := f3() {
|
||||||
|
println(z)
|
||||||
|
}
|
||||||
|
if _, _, _ := f3() {
|
||||||
|
}
|
||||||
|
if x, y, z := f4() {
|
||||||
|
println(x)
|
||||||
|
println(y)
|
||||||
|
println(z)
|
||||||
|
}
|
||||||
|
if x, y, _ := f4() {
|
||||||
|
println(x)
|
||||||
|
println(y)
|
||||||
|
}
|
||||||
|
if x, _, z := f4() {
|
||||||
|
println(x)
|
||||||
|
println(z)
|
||||||
|
}
|
||||||
|
if x, _, _ := f4() {
|
||||||
|
println(x)
|
||||||
|
}
|
||||||
|
if _, y, z := f4() {
|
||||||
|
println(y)
|
||||||
|
println(z)
|
||||||
|
}
|
||||||
|
if _, y, _ := f4() {
|
||||||
|
println(y)
|
||||||
|
}
|
||||||
|
if _, _, z := f4() {
|
||||||
|
println(z)
|
||||||
|
}
|
||||||
|
if _, _, _ := f4() {
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user