You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Discarding first inline else capture on tagged union switch when using labeled switch fails to compile #26038
Sorry for the bulky issue name :< The bug is just kinda that specific.
constTaggedUnion=union(enum) {
a: u32,
b: i32,
c: void,
};
// In some function...consttu: TaggedUnion= .{ .a=15 };
sw: switch (tu) {
inlineelse=>|_, tag| {
// Code body doesn't matter, but presumably you're using tag somewhere._=tag;
continue :swnext; // Any continue value still fails
},
}
The code above will fail to compile with no sensible error (only returning error code 1), despite the fact that this should be valid as far as I can tell.
Replacing inline else => |_, tag| with inline else => |value, tag| and then discarding value using _ = value compiles just fine.
I don't personally see any use cases where this would actually matter, but it definitely shouldn't just crash without explanation like it does.
Expected Behavior
The given code should compile, or if it's not valid for some reason, it should return an actual compiler error instead of simply crashing the compiler.
Sure!
First off, to even get this kind of error trace you need a debug build of the compiler, further details are in the build from source section of the README.
Everything below 'Compiler crash context:' (all of the % stuff) is ZIR (zig intermediate representation), it's basically zig code that's already been parsed and turned into a series of instructions, but has not yet been semantically analyzed (basically type resolution/checking and everything comptime related). For more details on how ZIR works and how it's semantically analyzed have a look at this great post by mlugg.
The little > points out where something went wrong. In this case it's pointed at a switch_block instruction, so the compiler crashed while trying to semantically analyze a switch statement.
From there on it's just a normal stack trace. I shortened it a bit because the rest isn't really relevant, the issue is already known anyway. What's happening is that analyzeTagCapture is accessing an undefined value (see #24792 for more details):
fnanalyzeTagCapture(
spa: SwitchProngAnalysis,
block: *Block,
capture_src: LazySrcLoc,
inline_case_capture: Air.Inst.Ref,
) CompileError!Air.Inst.Ref {
constsema=spa.sema;
constpt=sema.pt;
constzcu=pt.zcu;
constoperand_ty=switch (spa.operand) {
.simple=>|s|sema.typeOf(s.by_val),
.loop=>|l|ty: {
constalloc_ty=sema.typeOf(l.operand_alloc); // <- operand_alloc is undefined at this point, so alloc_ty is also a garbage valueconstalloc_child=alloc_ty.childType(zcu); // <- the crash happens here, might as well have happened a line earlierif (l.operand_is_ref) break :tyalloc_child.childType(zcu);
break :tyalloc_child;
},
};
[...]
Activity
Justus2308 commentedon Nov 24, 2025
Same issue as #24789
This is indeed a compiler bug your code should be valid :)
error trace etc
Cassunshine commentedon Nov 24, 2025
😔 i swear i searched for an existing issue, dangit
well good to know i'm not crazy!
ProCoder445 commentedon Nov 24, 2025
Can you please explain the compiler's error trace? I'm not familiar enough with the language to understand it. I'm new to the zig world,, hello!
Justus2308 commentedon Nov 24, 2025
Sure!
First off, to even get this kind of error trace you need a debug build of the compiler, further details are in the build from source section of the README.
Everything below 'Compiler crash context:' (all of the
%stuff) is ZIR (zig intermediate representation), it's basically zig code that's already been parsed and turned into a series of instructions, but has not yet been semantically analyzed (basically type resolution/checking and everything comptime related). For more details on how ZIR works and how it's semantically analyzed have a look at this great post by mlugg.The little
>points out where something went wrong. In this case it's pointed at aswitch_blockinstruction, so the compiler crashed while trying to semantically analyze a switch statement.From there on it's just a normal stack trace. I shortened it a bit because the rest isn't really relevant, the issue is already known anyway. What's happening is that
analyzeTagCaptureis accessing anundefinedvalue (see #24792 for more details):https://github.com/ziglang/zig/blob/3c647ca6bb987c496652fd6bf279ef2625f41821/src/Sema.zig#L10562-L10579
Welcome to the zig world! If you have more questions I'd recommend joining a zig community