mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: fix match expr with optional (#15658)
This commit is contained in:
parent
cee8b38221
commit
0c84ad847e
@ -28,7 +28,7 @@ fn (mut g Gen) need_tmp_var_in_match(node ast.MatchExpr) bool {
|
||||
if branch.stmts.len == 1 {
|
||||
if branch.stmts[0] is ast.ExprStmt {
|
||||
stmt := branch.stmts[0] as ast.ExprStmt
|
||||
if stmt.expr in [ast.CallExpr, ast.IfExpr, ast.MatchExpr]
|
||||
if stmt.expr in [ast.CallExpr, ast.IfExpr, ast.MatchExpr, ast.StructInit]
|
||||
|| (stmt.expr is ast.IndexExpr
|
||||
&& (stmt.expr as ast.IndexExpr).or_expr.kind != .absent) {
|
||||
return true
|
||||
|
17
vlib/v/tests/match_expr_with_struct_init_test.v
Normal file
17
vlib/v/tests/match_expr_with_struct_init_test.v
Normal file
@ -0,0 +1,17 @@
|
||||
struct Test {
|
||||
a string
|
||||
}
|
||||
|
||||
fn test_match_expr_with_struct_init() {
|
||||
a := map[string]string{}
|
||||
b := match 'test' {
|
||||
'test' {
|
||||
Test{a['test'] or { '' }}
|
||||
}
|
||||
else {
|
||||
Test{''}
|
||||
}
|
||||
}
|
||||
println(b)
|
||||
assert b.a == ''
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user