diff --git a/src/check_expr.cpp b/src/check_expr.cpp index 332277701..3f8f4f71b 100644 --- a/src/check_expr.cpp +++ b/src/check_expr.cpp @@ -10234,15 +10234,21 @@ gb_internal ExprKind check_or_else_expr(CheckerContext *c, Operand *o, Ast *node } } } else { - check_or_else_expr_no_value_error(c, name, x, type_hint); + if (right_type == nullptr || !y_is_diverging) { + check_or_else_expr_no_value_error(c, name, x, type_hint); + } } - if (left_type == nullptr) { - left_type = t_invalid; - } - o->mode = Addressing_Value; - o->type = left_type; o->expr = node; + o->type = left_type; + if (left_type != nullptr) { + o->mode = Addressing_Value; + } else if (y_is_diverging) { + o->mode = Addressing_NoValue; + } else { + o->mode = Addressing_Value; + o->type = t_invalid; + } return Expr_Expr; } diff --git a/src/llvm_backend_utility.cpp b/src/llvm_backend_utility.cpp index c71d16122..afa773f1e 100644 --- a/src/llvm_backend_utility.cpp +++ b/src/llvm_backend_utility.cpp @@ -408,7 +408,9 @@ gb_internal void lb_emit_try_lhs_rhs(lbProcedure *p, Ast *arg, TypeAndValue cons lbValue value = lb_build_expr(p, arg); if (is_type_tuple(value.type)) { i32 n = cast(i32)(value.type->Tuple.variables.count-1); - if (value.type->Tuple.variables.count == 2) { + if (value.type->Tuple.variables.count == 1) { + // No lhs + } else if (value.type->Tuple.variables.count == 2) { lhs = lb_emit_tuple_ev(p, value, 0); } else { lbAddr lhs_addr = lb_add_local_generated(p, tv.type, false); @@ -513,7 +515,10 @@ gb_internal lbValue lb_emit_or_else(lbProcedure *p, Ast *arg, Ast *else_expr, Ty lb_emit_unreachable(p); // add just in case lb_start_block(p, then); - return lb_emit_conv(p, lhs, type); + if (lhs.value != nullptr && type != nullptr) { + return lb_emit_conv(p, lhs, type); + } + return {}; } else { if (lb_is_type_trivial(type) && lb_is_expr_trivial(else_expr)) { lbValue has_value = lb_emit_try_has_value(p, rhs);