mirror of
https://github.com/ziglang/zig.git
synced 2026-02-12 20:37:54 +00:00
Sema: handle opt_payload in beginComptimePtrLoad
This commit is contained in:
parent
0616d2966a
commit
510b891d27
@ -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,
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user