diff --git a/src/ir.cpp b/src/ir.cpp index 16e37d61ac..4e6752a0fa 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -15487,6 +15487,7 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s if (actual_elem_type->id == ZigTypeIdOptional && value_type->id != ZigTypeIdOptional && value_type->id != ZigTypeIdNull) { + 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) { if (value_type->id == ZigTypeIdErrorSet) { diff --git a/test/stage1/behavior/misc.zig b/test/stage1/behavior/misc.zig index 613bb9ac54..cffe1faebe 100644 --- a/test/stage1/behavior/misc.zig +++ b/test/stage1/behavior/misc.zig @@ -488,7 +488,7 @@ test "@typeName" { expect(mem.eql(u8, @typeName(i64), "i64")); expect(mem.eql(u8, @typeName(*usize), "*usize")); // https://github.com/ziglang/zig/issues/675 - expectEqualSlices(u8, "behavior.misc.TypeFromFn(u8)", @typeName(TypeFromFn(u8))); + expect(mem.eql(u8, "behavior.misc.TypeFromFn(u8)", @typeName(TypeFromFn(u8)))); expect(mem.eql(u8, @typeName(Struct), "Struct")); expect(mem.eql(u8, @typeName(Union), "Union")); expect(mem.eql(u8, @typeName(Enum), "Enum")); @@ -741,3 +741,16 @@ test "peer result location with typed parent, runtime condition, comptime prongs expect(S.doTheTest(0) == 1234); expect(S.doTheTest(1) == 1234); } + +test "nested optional field in struct" { + const S2 = struct { + y: u8, + }; + const S1 = struct { + x: ?S2, + }; + var s = S1{ + .x = S2{ .y = 127 }, + }; + expect(s.x.?.y == 127); +}