authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2019-09-12 23:02:15+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-09-24 00:31:35-04:00
log93367adaa770944a13a8d44628dfefe1abe91906
tree993dfd70ae5290809b635ba9ee42cae6c949e8fa
parent0bdc85181cbe1954dac7e96c5ab4b2fe209b9098
signaturelock-open Commit is signed but in an unrecognized format.

Fix assignment to optional payload

Closes #3081

2 files changed, 15 insertions(+), 1 deletions(-)

src/ir.cpp+1
......@@ -15487,6 +15487,7 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s
1548715487 if (actual_elem_type->id == ZigTypeIdOptional && value_type->id != ZigTypeIdOptional &&
1548815488 value_type->id != ZigTypeIdNull)
1548915489 {
15490 result_loc_pass1->written = false;
1549015491 return ir_analyze_unwrap_optional_payload(ira, suspend_source_instr, result_loc, false, true);
1549115492 } else if (actual_elem_type->id == ZigTypeIdErrorUnion && value_type->id != ZigTypeIdErrorUnion) {
1549215493 if (value_type->id == ZigTypeIdErrorSet) {
test/stage1/behavior/misc.zig+14-1
......@@ -488,7 +488,7 @@ test "@typeName" {
488488 expect(mem.eql(u8, @typeName(i64), "i64"));
489489 expect(mem.eql(u8, @typeName(*usize), "*usize"));
490490 // https://github.com/ziglang/zig/issues/675
491 expectEqualSlices(u8, "behavior.misc.TypeFromFn(u8)", @typeName(TypeFromFn(u8)));
491 expect(mem.eql(u8, "behavior.misc.TypeFromFn(u8)", @typeName(TypeFromFn(u8))));
492492 expect(mem.eql(u8, @typeName(Struct), "Struct"));
493493 expect(mem.eql(u8, @typeName(Union), "Union"));
494494 expect(mem.eql(u8, @typeName(Enum), "Enum"));
......@@ -741,3 +741,16 @@ test "peer result location with typed parent, runtime condition, comptime prongs
741741 expect(S.doTheTest(0) == 1234);
742742 expect(S.doTheTest(1) == 1234);
743743}
744
745test "nested optional field in struct" {
746 const S2 = struct {
747 y: u8,
748 };
749 const S1 = struct {
750 x: ?S2,
751 };
752 var s = S1{
753 .x = S2{ .y = 127 },
754 };
755 expect(s.x.?.y == 127);
756}