mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: fix using brackets for match expression (#6768)
This commit is contained in:
parent
0d8114e14d
commit
125650c986
@ -2820,12 +2820,17 @@ fn (mut g Gen) match_expr(node ast.MatchExpr) {
|
||||
g.expr(node.cond)
|
||||
g.writeln(';')
|
||||
g.write(cur_line)
|
||||
if is_expr {
|
||||
// brackets needed otherwise '?' will apply to everything on the left
|
||||
g.write('(')
|
||||
}
|
||||
if node.is_sum_type {
|
||||
g.match_expr_sumtype(node, is_expr, cond_var)
|
||||
} else {
|
||||
g.match_expr_classic(node, is_expr, cond_var)
|
||||
}
|
||||
if is_expr {
|
||||
g.write(')')
|
||||
g.decrement_inside_ternary()
|
||||
}
|
||||
}
|
||||
|
@ -222,3 +222,10 @@ fn test_match_sumtype_multiple_types() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn test_sub_expression() {
|
||||
b := false && match 1 {0 {true} else {true}}
|
||||
assert !b
|
||||
c := true || match 1 {0 {false} else {false}}
|
||||
assert c
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user