Sema: resolve lazy values in switch prong items

Closes #14330
This commit is contained in:
Veikka Tuominen 2023-01-16 14:16:47 +02:00
parent 6b037bad59
commit 8b35f09f4a
2 changed files with 15 additions and 0 deletions

View File

@ -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 => {

View File

@ -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();
}