fix regression with optionals and globals

This commit is contained in:
Andrew Kelley 2020-01-13 17:42:01 -05:00
parent b952b84486
commit 6a8c9f7306
No known key found for this signature in database
GPG Key ID: 7C5F548F728501A9
2 changed files with 10 additions and 7 deletions

View File

@ -17606,12 +17606,15 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s
if (actual_elem_type->id == ZigTypeIdOptional && value_type->id != ZigTypeIdOptional &&
value_type->id != ZigTypeIdNull)
{
bool has_bits;
if ((err = type_has_bits2(ira->codegen, value_type, &has_bits)))
return ira->codegen->invalid_instruction;
if (has_bits) {
result_loc_pass1->written = false;
return ir_analyze_unwrap_optional_payload(ira, suspend_source_instr, result_loc, false, true);
bool same_comptime_repr = types_have_same_zig_comptime_repr(ira->codegen, actual_elem_type, value_type);
if (!same_comptime_repr) {
bool has_bits;
if ((err = type_has_bits2(ira->codegen, value_type, &has_bits)))
return ira->codegen->invalid_instruction;
if (has_bits) {
result_loc_pass1->written = false;
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) {
bool has_bits;

View File

@ -82,7 +82,7 @@ comptime {
_ = @import("behavior/namespace_depends_on_compile_var.zig");
_ = @import("behavior/new_stack_call.zig");
_ = @import("behavior/null.zig");
//_ = @import("behavior/optional.zig");
_ = @import("behavior/optional.zig");
_ = @import("behavior/pointers.zig");
_ = @import("behavior/popcount.zig");
_ = @import("behavior/ptrcast.zig");