cgen: format generated code in match_expr() (#10397)

pull/10428/head
yuyi 2021-06-13 02:14:08 +08:00 committed by GitHub
parent b7f9bc2a96
commit 0e34ce2759
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 2 deletions

View File

@ -1026,8 +1026,10 @@ fn (mut g Gen) stmts_with_tmp_var(stmts []ast.Stmt, tmp_var string) {
g.skip_stmt_pos = true g.skip_stmt_pos = true
g.write('$tmp_var = ') g.write('$tmp_var = ')
g.stmt(stmt) g.stmt(stmt)
if !g.out.last_n(2).contains(';') {
g.writeln(';') g.writeln(';')
} }
}
} else { } else {
g.stmt(stmt) g.stmt(stmt)
if g.inside_if_optional && stmt is ast.ExprStmt { if g.inside_if_optional && stmt is ast.ExprStmt {
@ -4086,7 +4088,7 @@ fn (mut g Gen) match_expr(node ast.MatchExpr) {
} }
if need_tmp_var { if need_tmp_var {
g.empty_line = true g.empty_line = true
cur_line = g.go_before_stmt(0) cur_line = g.go_before_stmt(0).trim_left(' \t')
tmp_var = g.new_tmp_var() tmp_var = g.new_tmp_var()
g.writeln('${g.typ(node.return_type)} $tmp_var;') g.writeln('${g.typ(node.return_type)} $tmp_var;')
} }