aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVeikka Tuominen <git@vexu.eu>2022-11-16 19:13:31 +0200
committerVeikka Tuominen <git@vexu.eu>2022-11-20 20:25:11 +0200
commit510b891d271bc69c64e4be8b3e008c8a51a235e7 (patch)
treeb26b14482f56bdb663f1dae2b31b70e18bc69b74
parent0616d2966a623a005891a2037b49cc2b8ad5b9c4 (diff)
downloadzig-510b891d271bc69c64e4be8b3e008c8a51a235e7.tar.gz
zig-510b891d271bc69c64e4be8b3e008c8a51a235e7.zip
Sema: handle `opt_payload` in `beginComptimePtrLoad`
-rw-r--r--src/Sema.zig4
-rw-r--r--test/behavior/type_info.zig7
2 files changed, 11 insertions, 0 deletions
diff --git a/src/Sema.zig b/src/Sema.zig
index 5151904f0b..90de77a57e 100644
--- a/src/Sema.zig
+++ b/src/Sema.zig
@@ -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,
diff --git a/test/behavior/type_info.zig b/test/behavior/type_info.zig
index 80a3c7210a..af1b740834 100644
--- a/test/behavior/type_info.zig
+++ b/test/behavior/type_info.zig
@@ -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);
+ }
+}