1
0
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:
Felipe Pena 2023-01-29 07:11:30 -03:00 committed by GitHub
parent 9a86456365
commit cb79e57c1a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 1 deletions

View File

@ -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 {

View 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
}
}
}