commit 456f3c026b3d6fb289f42e442b202e0be152c9d3 (tree)
parent 3ce857d0543780e96bfd50d75d53d870ff308fef
Author: mlugg <mlugg@mlugg.co.uk>
Date: Wed, 5 Feb 2025 19:08:05 +0000
Sema: fix crash on `@tagName` of undefined enum literal
Resolves: #20826
Diffstat:
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/src/Sema.zig b/src/Sema.zig
@@ -21401,7 +21401,7 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
try operand_ty.resolveLayout(pt);
const enum_ty = switch (operand_ty.zigTypeTag(zcu)) {
.enum_literal => {
- const val = try sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, operand, undefined);
+ const val = (try sema.resolveDefinedValue(block, operand_src, operand)).?;
const tag_name = ip.indexToKey(val.toIntern()).enum_literal;
return sema.addNullTerminatedStrLit(tag_name);
},
diff --git a/test/cases/compile_errors/tagName_on_undef_enum_literal.zig b/test/cases/compile_errors/tagName_on_undef_enum_literal.zig
@@ -0,0 +1,8 @@
+comptime {
+ const undef: @Type(.enum_literal) = undefined;
+ _ = @tagName(undef);
+}
+
+// error
+//
+// :3:18: error: use of undefined value here causes undefined behavior