Commit 456f3c026b

mlugg <mlugg@mlugg.co.uk>
2025-02-05 20:08:05
Sema: fix crash on `@tagName` of undefined enum literal
Resolves: #20826
1 parent 3ce857d
Changed files (2)
src
test
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);
         },
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