authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-12-05 18:17:33+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-12-07 14:48:24+02:00
logddce76059b1631f3eddc3c09615b26698210ba9e
tree316c594c888a459f88a50e9015cee4ac53f7ab66
parentd078d08e4f661c1b0bee31d7852e5e6058d54b11

Sema: add error for `@tagName` on empty enum


1 files changed, 7 insertions(+), 0 deletions(-)

src/Sema.zig+7
...@@ -17877,6 +17877,13 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -17877,6 +17877,13 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
17877 operand_ty.fmt(mod),17877 operand_ty.fmt(mod),
17878 }),17878 }),
17879 };17879 };
17880 if (enum_ty.enumFieldCount() == 0) {
17881 // TODO I don't think this is the correct way to handle this but
17882 // it prevents a crash.
17883 return sema.fail(block, operand_src, "cannot get @tagName of empty enum '{}'", .{
17884 enum_ty.fmt(mod),
17885 });
17886 }
17880 const enum_decl_index = enum_ty.getOwnerDecl();17887 const enum_decl_index = enum_ty.getOwnerDecl();
17881 const casted_operand = try sema.coerce(block, enum_ty, operand, operand_src);17888 const casted_operand = try sema.coerce(block, enum_ty, operand, operand_src);
17882 if (try sema.resolveDefinedValue(block, operand_src, casted_operand)) |val| {17889 if (try sema.resolveDefinedValue(block, operand_src, casted_operand)) |val| {