authorgravatar for 51252236+xdBronch@users.noreply.github.comxdBronch <51252236+xdBronch@users.noreply.github.com> 2023-07-28 22:28:55-04:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2023-07-28 22:28:55-04:00
log2826f78a61c014b7cfb9e7ce1a7efce31b24d0c9
treec002d065f4565e044ebc91be62a9642473c8b6ec
parentbde6e075dfc202fdcfa21ec9c2d90941460b002e
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

suggest using else when '_' is used for exhaustive enums (#16583)


3 files changed, 9 insertions(+), 0 deletions(-)

src/Sema.zig+7
...@@ -10791,6 +10791,13 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -10791,6 +10791,13 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
10791 "'_' prong here",10791 "'_' prong here",
10792 .{},10792 .{},
10793 );10793 );
10794 try sema.errNote(
10795 block,
10796 src,
10797 msg,
10798 "consider using 'else'",
10799 .{},
10800 );
10794 break :msg msg;10801 break :msg msg;
10795 };10802 };
10796 return sema.failWithOwnedErrorMsg(msg);10803 return sema.failWithOwnedErrorMsg(msg);
test/cases/compile_errors/switching_with_exhaustive_enum_has___prong_.zig+1
...@@ -17,3 +17,4 @@ pub export fn entry() void {...@@ -17,3 +17,4 @@ pub export fn entry() void {
17//17//
18// :7:5: error: '_' prong only allowed when switching on non-exhaustive enums18// :7:5: error: '_' prong only allowed when switching on non-exhaustive enums
19// :10:11: note: '_' prong here19// :10:11: note: '_' prong here
20// :7:5: note: consider using 'else'
test/cases/compile_errors/switching_with_non-exhaustive_enums.zig+1
...@@ -40,3 +40,4 @@ pub export fn entry3() void {...@@ -40,3 +40,4 @@ pub export fn entry3() void {
40// :19:5: error: switch on non-exhaustive enum must include 'else' or '_' prong40// :19:5: error: switch on non-exhaustive enum must include 'else' or '_' prong
41// :26:5: error: '_' prong only allowed when switching on non-exhaustive enums41// :26:5: error: '_' prong only allowed when switching on non-exhaustive enums
42// :29:11: note: '_' prong here42// :29:11: note: '_' prong here
43// :26:5: note: consider using 'else'