Commit 2826f78a61

xdBronch <51252236+xdBronch@users.noreply.github.com>
2023-07-29 04:28:55
suggest using else when '_' is used for exhaustive enums (#16583)
1 parent bde6e07
src/Sema.zig
@@ -10791,6 +10791,13 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
                 "'_' prong here",
                 .{},
             );
+            try sema.errNote(
+                block,
+                src,
+                msg,
+                "consider using 'else'",
+                .{},
+            );
             break :msg msg;
         };
         return sema.failWithOwnedErrorMsg(msg);
test/cases/compile_errors/switching_with_exhaustive_enum_has___prong_.zig
@@ -17,3 +17,4 @@ pub export fn entry() void {
 //
 // :7:5: error: '_' prong only allowed when switching on non-exhaustive enums
 // :10:11: note: '_' prong here
+// :7:5: note: consider using 'else'
test/cases/compile_errors/switching_with_non-exhaustive_enums.zig
@@ -40,3 +40,4 @@ pub export fn entry3() void {
 // :19:5: error: switch on non-exhaustive enum must include 'else' or '_' prong
 // :26:5: error: '_' prong only allowed when switching on non-exhaustive enums
 // :29:11: note: '_' prong here
+// :26:5: note: consider using 'else'