cgen: edge case for multi-returns

pull/5395/head
Emily Hudson 2020-06-15 21:30:16 +01:00 committed by GitHub
parent 41e0561b05
commit 49d7a151b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 0 deletions

View File

@ -2355,6 +2355,14 @@ fn (mut g Gen) return_statement(node ast.Return) {
g.write('return ')
styp = g.typ(g.fn_decl.return_type)
}
// Edge case handling for 2 multi returns of the same type
if node.exprs.len == 1 && g.expr_is_multi_return_call(node.exprs[0]) {
g.go_before_stmt(0)
g.write('return ')
g.expr(node.exprs[0])
g.writeln(';')
return
}
// Use this to keep the tmp assignments in order
mut multi_unpack := ''
g.write('($styp){')