Sema: handle opt_payload in beginComptimePtrLoad

This commit is contained in:
Veikka Tuominen 2022-11-16 19:13:31 +02:00
parent 0616d2966a
commit 510b891d27
2 changed files with 11 additions and 0 deletions

View File

@ -26555,6 +26555,10 @@ fn beginComptimePtrLoad(
.null_value => {
return sema.fail(block, src, "attempt to use null value", .{});
},
.opt_payload => blk: {
const opt_payload = ptr_val.castTag(.opt_payload).?.data;
break :blk try sema.beginComptimePtrLoad(block, src, opt_payload, null);
},
.zero,
.one,

View File

@ -565,3 +565,10 @@ test "typeInfo resolves usingnamespace declarations" {
try expect(@typeInfo(B).Struct.decls.len == 2);
//a
}
test "value from struct @typeInfo default_value can be loaded at comptime" {
comptime {
const a = @typeInfo(@TypeOf(.{ .foo = @as(u8, 1) })).Struct.fields[0].default_value;
try expect(@ptrCast(*const u8, a).* == 1);
}
}