cgen: fix line number generation on match (#7292)

pull/7296/head
Daniel Däschle 2020-12-12 23:08:45 +01:00 committed by GitHub
parent 4d025582c0
commit fb9db11a00
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 5 deletions

View File

@ -3098,7 +3098,7 @@ fn (mut g Gen) match_expr(node ast.MatchExpr) {
cond_var := g.new_tmp_var()
g.write('${g.typ(node.cond_type)} $cond_var = ')
g.expr(node.cond)
g.writeln(';')
g.writeln('; ')
g.write(cur_line)
if is_expr {
// brackets needed otherwise '?' will apply to everything on the left
@ -3128,19 +3128,24 @@ fn (mut g Gen) match_expr_sumtype(node ast.MatchExpr, is_expr bool, cond_var str
// TODO too many branches. maybe separate ?: matches
g.write(' : ')
} else {
g.writeln(' else {')
g.writeln('')
g.write_v_source_line_info(branch.pos)
g.writeln('else {')
}
} else {
if j > 0 || sumtype_index > 0 {
if is_expr {
g.write(' : ')
} else {
g.write(' else ')
g.writeln('')
g.write_v_source_line_info(branch.pos)
g.write('else ')
}
}
if is_expr {
g.write('(')
} else {
g.write_v_source_line_info(branch.pos)
g.write('if (')
}
g.write(cond_var)
@ -3184,7 +3189,9 @@ fn (mut g Gen) match_expr_classic(node ast.MatchExpr, is_expr bool, cond_var str
// TODO too many branches. maybe separate ?: matches
g.write(' : ')
} else {
g.writeln(' else {')
g.writeln('')
g.write_v_source_line_info(branch.pos)
g.writeln('else {')
}
}
} else {
@ -3192,12 +3199,15 @@ fn (mut g Gen) match_expr_classic(node ast.MatchExpr, is_expr bool, cond_var str
if is_expr {
g.write(' : ')
} else {
g.write(' else ')
g.writeln('')
g.write_v_source_line_info(branch.pos)
g.write('else ')
}
}
if is_expr {
g.write('(')
} else {
g.write_v_source_line_info(branch.pos)
g.write('if (')
}
for i, expr in branch.exprs {