Commit 1401890ed5
Changed files (2)
src
test
cases
compile_errors
src/Sema.zig
@@ -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);
}
test/cases/compile_errors/switch_on_slice.zig
@@ -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'