Commit 8b35f09f4a

Veikka Tuominen <git@vexu.eu>
2023-01-16 13:16:47
Sema: resolve lazy values in switch prong items
Closes #14330
1 parent 6b037ba
Changed files (2)
src
test
behavior
src/Sema.zig
@@ -11288,6 +11288,7 @@ fn resolveSwitchItemVal(
     // Only if we know for sure we need to report a compile error do we resolve the
     // full source locations.
     if (sema.resolveConstValue(block, .unneeded, item, "")) |val| {
+        try sema.resolveLazyValue(val);
         return TypedValue{ .ty = item_ty, .val = val };
     } else |err| switch (err) {
         error.NeededSourceLocation => {
test/behavior/switch.zig
@@ -686,3 +686,17 @@ test "enum value without tag name used as switch item" {
         _ => return error.TestFailed,
     }
 }
+
+test "switch item sizeof" {
+    const S = struct {
+        fn doTheTest() !void {
+            var a: usize = 0;
+            switch (a) {
+                @sizeOf(struct {}) => {},
+                else => return error.TestFailed,
+            }
+        }
+    };
+    try S.doTheTest();
+    comptime try S.doTheTest();
+}