v2: update MatchExpr in vfmt

pull/3937/head
Joe Conigliaro 2020-03-04 22:14:37 +11:00
parent e71948461e
commit 5872961124
1 changed files with 23 additions and 14 deletions

View File

@ -434,21 +434,30 @@ fn (f mut Fmt) expr(node ast.Expr) {
f.expr(it.cond) f.expr(it.cond)
f.writeln(' {') f.writeln(' {')
f.indent++ f.indent++
for i, expr in it.match_exprs { for i, branch in it.branches {
// normal branch
if i < it.branches.len - 1 {
for j,expr in branch.exprs {
f.expr(expr) f.expr(expr)
if j < branch.exprs.len - 1 {
f.write(', ')
}
}
f.writeln(' {') f.writeln(' {')
f.stmts(it.blocks[i].stmts) f.stmts(branch.stmts)
f.writeln('}') f.writeln('}')
} }
// else branch
else_stmts := it.blocks[it.blocks.len - 1].stmts else {
if (else_stmts.len == 0) { if (branch.stmts.len == 0) {
f.writeln('else {}') f.writeln('else {}')
} else { } else {
f.writeln('else {') f.writeln('else {')
f.stmts(else_stmts) f.stmts(branch.stmts)
f.writeln('}') f.writeln('}')
} }
}
}
f.indent-- f.indent--
f.write('}') f.write('}')
} }