Sema: fix crash on @tagName of undefined enum literal

Resolves: #20826
This commit is contained in:
mlugg 2025-02-05 19:08:05 +00:00
parent 3ce857d054
commit 456f3c026b
No known key found for this signature in database
GPG Key ID: 3F5B7DCCBF4AF02E
2 changed files with 9 additions and 1 deletions

View File

@ -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);
},

View File

@ -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