zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit a221b2fbf2829e2e8ba5ecd2d7569e619a66d69b (tree)
parent e62aac3ec4b21da20d7c57d937e508f2929138d0
Author: wooster0 <wooster0@proton.me>
Date:   Sat,  7 Dec 2024 17:56:48 +0900

Sema: fix use of Zcu.LazySrcLoc in error message

It currently prints as:

:3:18: error: untagged union 'Zcu.LazySrcLoc{ .base_node_inst = InternPool.TrackedInst.Index(104), .offset = Zcu.LazySrcLoc.Offset{ .node_offset = Zcu.LazySrcLoc.Offset.TracedOffset{ .x = -2, .trace = (value tracing disabled) } } }' cannot be converted to integer

Diffstat:
Msrc/Sema.zig | 2+-
Atest/cases/compile_errors/untagged_union_integer_conversion.zig | 11+++++++++++
2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/src/Sema.zig b/src/Sema.zig @@ -8999,7 +8999,7 @@ fn zirIntFromEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError block, operand_src, "untagged union '{}' cannot be converted to integer", - .{src}, + .{operand_ty.fmt(pt)}, ); }; diff --git a/test/cases/compile_errors/untagged_union_integer_conversion.zig b/test/cases/compile_errors/untagged_union_integer_conversion.zig @@ -0,0 +1,11 @@ +const UntaggedUnion = union {}; +comptime { + @intFromEnum(@as(UntaggedUnion, undefined)); +} + +// error +// backend=stage2 +// target=native +// +// :3:18: error: untagged union 'tmp.UntaggedUnion' cannot be converted to integer +// :1:23: note: union declared here