mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: fix generated code for match bar()?.a {
(matchexpr with call expr using propagation) (#17150)
This commit is contained in:
parent
9a86456365
commit
cb79e57c1a
@ -67,7 +67,9 @@ fn (mut g Gen) match_expr(node ast.MatchExpr) {
|
||||
}
|
||||
if node.cond in [ast.Ident, ast.IntegerLiteral, ast.StringLiteral, ast.FloatLiteral]
|
||||
|| (node.cond is ast.SelectorExpr
|
||||
&& (node.cond as ast.SelectorExpr).or_block.kind == .absent) {
|
||||
&& (node.cond as ast.SelectorExpr).or_block.kind == .absent
|
||||
&& ((node.cond as ast.SelectorExpr).expr !is ast.CallExpr
|
||||
|| ((node.cond as ast.SelectorExpr).expr as ast.CallExpr).or_block.kind == .absent)) {
|
||||
cond_var = g.expr_string(node.cond)
|
||||
} else {
|
||||
line := if is_expr {
|
||||
|
32
vlib/v/tests/match_expr_with_opt_result_test.v
Normal file
32
vlib/v/tests/match_expr_with_opt_result_test.v
Normal file
@ -0,0 +1,32 @@
|
||||
struct Foo {
|
||||
pub:
|
||||
a int
|
||||
}
|
||||
|
||||
fn foo() !Foo {
|
||||
return Foo{1}
|
||||
}
|
||||
|
||||
fn bar() ?Foo {
|
||||
return Foo{2}
|
||||
}
|
||||
|
||||
fn test_main() {
|
||||
match foo()!.a {
|
||||
1 {
|
||||
assert true
|
||||
}
|
||||
else {
|
||||
assert false
|
||||
}
|
||||
}
|
||||
|
||||
match bar()?.a {
|
||||
2 {
|
||||
assert true
|
||||
}
|
||||
else {
|
||||
assert false
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user