Commit 510b891d27

Veikka Tuominen <git@vexu.eu>
2022-11-16 18:13:31
Sema: handle `opt_payload` in `beginComptimePtrLoad`
1 parent 0616d29
Changed files (2)
src
test
behavior
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,
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);
+    }
+}