Fix lb_emit_try

This commit is contained in:
gingerBill
2021-07-04 01:47:43 +01:00
parent e8f2c5a48a
commit 5f71c41582
+9 -5
View File
@@ -9612,18 +9612,22 @@ lbValue lb_emit_try(lbProcedure *p, AstCallExpr *ce, TypeAndValue const &tv) {
bool return_by_pointer = ft->ret.kind == lbArg_Indirect; bool return_by_pointer = ft->ret.kind == lbArg_Indirect;
lbValue res = {}; lbValue res = {};
if (return_count == 1) {
Entity *e = tuple->variables[0];
res = lb_emit_conv(p, rhs, e->type);
if (p->type->Proc.has_named_results) { if (p->type->Proc.has_named_results) {
Entity *e = tuple->variables[tuple->variables.count-1];
// NOTE(bill): store the named values before returning // NOTE(bill): store the named values before returning
if (e->token.string != "") { if (e->token.string != "") {
lbValue *found = map_get(&p->module->values, hash_entity(e)); lbValue *found = map_get(&p->module->values, hash_entity(e));
GB_ASSERT(found != nullptr); GB_ASSERT(found != nullptr);
lb_emit_store(p, *found, lb_emit_conv(p, res, e->type)); res = lb_emit_conv(p, rhs, e->type);
lb_emit_store(p, *found, res);
} }
} }
if (return_count == 1) {
Entity *e = tuple->variables[0];
if (res.value == nullptr) {
res = lb_emit_conv(p, rhs, e->type);
}
} else { } else {
GB_ASSERT(p->type->Proc.has_named_results); GB_ASSERT(p->type->Proc.has_named_results);
auto results = array_make<lbValue>(permanent_allocator(), 0, return_count); auto results = array_make<lbValue>(permanent_allocator(), 0, return_count);