Sema: add error for switch on slice

Closes #12651
This commit is contained in:
Veikka Tuominen
2022-08-28 13:11:33 +03:00
parent fc213e2d61
commit 1401890ed5
2 changed files with 16 additions and 0 deletions

View File

@@ -9003,6 +9003,9 @@ fn zirSwitchCond(
.ErrorSet,
.Enum,
=> {
if (operand_ty.isSlice()) {
return sema.fail(block, src, "switch on type '{}'", .{operand_ty.fmt(sema.mod)});
}
if ((try sema.typeHasOnePossibleValue(block, operand_src, operand_ty))) |opv| {
return sema.addConstant(operand_ty, opv);
}

View File

@@ -0,0 +1,13 @@
pub export fn entry() void {
var a: [:0]const u8 = "foo";
switch (a) {
"--version", "version" => unreachable,
else => {},
}
}
// error
// backend=stage2
// target=native
//
// :3:13: error: switch on type '[:0]const u8'