zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 8b35f09f4ae29eb2768d47e8a8bae0f4131d6bad (tree)
parent 6b037bad590bd6c319af336b6d3017c33d6834ba
Author: Veikka Tuominen <git@vexu.eu>
Date:   Mon, 16 Jan 2023 14:16:47 +0200

Sema: resolve lazy values in switch prong items

Closes #14330

Diffstat:
Msrc/Sema.zig | 1+
Mtest/behavior/switch.zig | 14++++++++++++++
2 files changed, 15 insertions(+), 0 deletions(-)

diff --git a/src/Sema.zig b/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 => { diff --git a/test/behavior/switch.zig b/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(); +}