authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-11-16 19:13:31+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-11-20 20:25:11+02:00
log510b891d271bc69c64e4be8b3e008c8a51a235e7
treeb26b14482f56bdb663f1dae2b31b70e18bc69b74
parent0616d2966a623a005891a2037b49cc2b8ad5b9c4

Sema: handle `opt_payload` in `beginComptimePtrLoad`


2 files changed, 11 insertions(+), 0 deletions(-)

src/Sema.zig+4
...@@ -26555,6 +26555,10 @@ fn beginComptimePtrLoad(...@@ -26555,6 +26555,10 @@ fn beginComptimePtrLoad(
26555 .null_value => {26555 .null_value => {
26556 return sema.fail(block, src, "attempt to use null value", .{});26556 return sema.fail(block, src, "attempt to use null value", .{});
26557 },26557 },
26558 .opt_payload => blk: {
26559 const opt_payload = ptr_val.castTag(.opt_payload).?.data;
26560 break :blk try sema.beginComptimePtrLoad(block, src, opt_payload, null);
26561 },
2655826562
26559 .zero,26563 .zero,
26560 .one,26564 .one,
test/behavior/type_info.zig+7
...@@ -565,3 +565,10 @@ test "typeInfo resolves usingnamespace declarations" {...@@ -565,3 +565,10 @@ test "typeInfo resolves usingnamespace declarations" {
565 try expect(@typeInfo(B).Struct.decls.len == 2);565 try expect(@typeInfo(B).Struct.decls.len == 2);
566 //a566 //a
567}567}
568
569test "value from struct @typeInfo default_value can be loaded at comptime" {
570 comptime {
571 const a = @typeInfo(@TypeOf(.{ .foo = @as(u8, 1) })).Struct.fields[0].default_value;
572 try expect(@ptrCast(*const u8, a).* == 1);
573 }
574}