fix result locations not handling undefined correctly

master
Andrew Kelley 2020-01-28 13:33:51 -05:00
parent 86da9346e4
commit 793d81c4e8
No known key found for this signature in database
GPG Key ID: 7C5F548F728501A9
1 changed files with 5 additions and 3 deletions

View File

@ -18668,14 +18668,16 @@ static IrInstGen *ir_resolve_result(IrAnalyze *ira, IrInst *suspend_source_instr
ir_assert(result_loc->value->type->id == ZigTypeIdPointer, suspend_source_instr); ir_assert(result_loc->value->type->id == ZigTypeIdPointer, suspend_source_instr);
ZigType *actual_elem_type = result_loc->value->type->data.pointer.child_type; ZigType *actual_elem_type = result_loc->value->type->data.pointer.child_type;
if (actual_elem_type->id == ZigTypeIdOptional && value_type->id != ZigTypeIdOptional && if (actual_elem_type->id == ZigTypeIdOptional && value_type->id != ZigTypeIdOptional &&
value_type->id != ZigTypeIdNull) value_type->id != ZigTypeIdNull && value_type->id != ZigTypeIdUndefined)
{ {
bool same_comptime_repr = types_have_same_zig_comptime_repr(ira->codegen, actual_elem_type, value_type); bool same_comptime_repr = types_have_same_zig_comptime_repr(ira->codegen, actual_elem_type, value_type);
if (!same_comptime_repr) { if (!same_comptime_repr) {
result_loc_pass1->written = was_written; result_loc_pass1->written = was_written;
return ir_analyze_unwrap_optional_payload(ira, suspend_source_instr, result_loc, false, true); return ir_analyze_unwrap_optional_payload(ira, suspend_source_instr, result_loc, false, true);
} }
} else if (actual_elem_type->id == ZigTypeIdErrorUnion && value_type->id != ZigTypeIdErrorUnion) { } else if (actual_elem_type->id == ZigTypeIdErrorUnion && value_type->id != ZigTypeIdErrorUnion &&
value_type->id != ZigTypeIdUndefined)
{
if (value_type->id == ZigTypeIdErrorSet) { if (value_type->id == ZigTypeIdErrorSet) {
return ir_analyze_unwrap_err_code(ira, suspend_source_instr, result_loc, true); return ir_analyze_unwrap_err_code(ira, suspend_source_instr, result_loc, true);
} else { } else {
@ -18683,7 +18685,7 @@ static IrInstGen *ir_resolve_result(IrAnalyze *ira, IrInst *suspend_source_instr
result_loc, false, true); result_loc, false, true);
ZigType *actual_payload_type = actual_elem_type->data.error_union.payload_type; ZigType *actual_payload_type = actual_elem_type->data.error_union.payload_type;
if (actual_payload_type->id == ZigTypeIdOptional && value_type->id != ZigTypeIdOptional && if (actual_payload_type->id == ZigTypeIdOptional && value_type->id != ZigTypeIdOptional &&
value_type->id != ZigTypeIdNull) value_type->id != ZigTypeIdNull && value_type->id != ZigTypeIdUndefined)
{ {
return ir_analyze_unwrap_optional_payload(ira, suspend_source_instr, unwrapped_err_ptr, false, true); return ir_analyze_unwrap_optional_payload(ira, suspend_source_instr, unwrapped_err_ptr, false, true);
} else { } else {