Sema: fix else branch check when switching on error set

This commit is contained in:
Veikka Tuominen 2022-03-12 11:25:37 +02:00
parent 98a01f99c9
commit 07cc2fce2a
2 changed files with 2 additions and 5 deletions

View File

@ -6972,7 +6972,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
return sema.failWithOwnedErrorMsg(block, msg);
}
if (special_prong == .@"else") {
if (special_prong == .@"else" and seen_errors.count() == operand_ty.errorSetNames().len) {
return sema.fail(
block,
special_prong_src,

View File

@ -610,14 +610,11 @@ test "switch on pointer type" {
}
test "switch on error set with single else" {
if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO
const S = struct {
fn doTheTest() !void {
var some: error{Foo} = error.Foo;
try expect(switch (some) {
else => |a| blk: {
a catch {};
else => blk: {
break :blk true;
},
});