mirror of
https://github.com/vlang/v.git
synced 2025-09-14 06:52:36 +03:00
This commit is contained in:
parent
bed827e663
commit
42538e19ae
2 changed files with 30 additions and 0 deletions
|
@ -601,6 +601,20 @@ fn (mut p Parser) mark_last_call_return_as_used(mut last_stmt ast.Stmt) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ast.InfixExpr {
|
||||||
|
// last stmt has infix expr with CallExpr: foo()? + 'a'
|
||||||
|
mut left_expr := last_stmt.expr.left
|
||||||
|
for {
|
||||||
|
if mut left_expr is ast.InfixExpr {
|
||||||
|
left_expr = left_expr.left
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if mut left_expr is ast.CallExpr {
|
||||||
|
left_expr.is_return_used = true
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
else {}
|
else {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
16
vlib/v/tests/options/option_last_call_test.v
Normal file
16
vlib/v/tests/options/option_last_call_test.v
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
fn test_main() {
|
||||||
|
assert some_func2(14)? + 'c' == 'aabcac'
|
||||||
|
}
|
||||||
|
|
||||||
|
fn some_func(i int) ?string {
|
||||||
|
return 'a'
|
||||||
|
}
|
||||||
|
|
||||||
|
fn some_func2(i int) ?string {
|
||||||
|
return match i {
|
||||||
|
12 { some_func(1)? + 'b' }
|
||||||
|
13 { some_func(1)? + 'b' + 'c' }
|
||||||
|
14 { 'a' + some_func(1)? + 'b' + 'c' + some_func(1)? }
|
||||||
|
else { none }
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue