| author | |
| committer | |
| log | 1401890ed5194aff3469be0b6919fd8fe2614c7b |
| tree | 7ee8a6f2d29ded139aa6a7d96edc97207b180f85 |
| parent | fc213e2d61c9ae6e643ddebf502c699abe4055e8 |
Closes #126512 files changed, 16 insertions(+), 0 deletions(-)
src/Sema.zig+3| ... | ... | @@ -9003,6 +9003,9 @@ fn zirSwitchCond( |
| 9003 | 9003 | .ErrorSet, |
| 9004 | 9004 | .Enum, |
| 9005 | 9005 | => { |
| 9006 | if (operand_ty.isSlice()) { | |
| 9007 | return sema.fail(block, src, "switch on type '{}'", .{operand_ty.fmt(sema.mod)}); | |
| 9008 | } | |
| 9006 | 9009 | if ((try sema.typeHasOnePossibleValue(block, operand_src, operand_ty))) |opv| { |
| 9007 | 9010 | return sema.addConstant(operand_ty, opv); |
| 9008 | 9011 | } |
test/cases/compile_errors/switch_on_slice.zig created+13| ... | ... | @@ -0,0 +1,13 @@ |
| 1 | pub export fn entry() void { | |
| 2 | var a: [:0]const u8 = "foo"; | |
| 3 | switch (a) { | |
| 4 | "--version", "version" => unreachable, | |
| 5 | else => {}, | |
| 6 | } | |
| 7 | } | |
| 8 | ||
| 9 | // error | |
| 10 | // backend=stage2 | |
| 11 | // target=native | |
| 12 | // | |
| 13 | // :3:13: error: switch on type '[:0]const u8' |