commit 2826f78a61c014b7cfb9e7ce1a7efce31b24d0c9 (tree)
parent bde6e075dfc202fdcfa21ec9c2d90941460b002e
Author: xdBronch <51252236+xdBronch@users.noreply.github.com>
Date: Fri, 28 Jul 2023 22:28:55 -0400
suggest using else when '_' is used for exhaustive enums (#16583)
Diffstat:
3 files changed, 9 insertions(+), 0 deletions(-)
diff --git a/src/Sema.zig b/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);
diff --git a/test/cases/compile_errors/switching_with_exhaustive_enum_has___prong_.zig b/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'
diff --git a/test/cases/compile_errors/switching_with_non-exhaustive_enums.zig b/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'