feat(t27b): lower switch expressions and negative const literals - #6353
Merged
Merged
Conversation
switch on an enum or integer operand lowers to a lazy select chain, so only the taken prong runs (#6328); the operand is evaluated once. Shapes the reference cannot compile are refused by name (not exhaustive, unreachable else, duplicate prong, prong, char prong #6329). `const X: i32 = -1;` lowers as the comptime int t27c prints. `f(x);` with a non-void f is refused where zig test analyzes the body (ExprCall(value ignored) statement), matching specs/fpga/bpsk.t27; bench blocks are no longer analysis roots, since t27c emits them as uncalled fns. Corpus vs t27c reference at f25dbee: counted 623 -> 629 / 720, checked pass 346 -> 352, mismatch 0 -> 0, no regressions. Closes #6352 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
This was referenced Oct 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #6352
Refs #6063
What
switchexpressions incli/t27b, on an enum or an integer operand.Selects, so only the taken prong runs (feat(t27b): lower if-expressions natively; refuse what t27c misprints #6328).else, or the last prong when every value is listed.ifthrough a newselect_vals.const X: i32 = -1;lowers as the comptime int that t27c's Zig backend prints. It was refused asExprLiteral(negative literal).t27c test-report:ExprSwitch(not exhaustive)ExprSwitch(unreachable else)ExprSwitch(duplicate prong)ExprSwitch(prong): unknown variant, int prong on an enum, out-of-range value, or ident prong on an intExprSwitch(char prong):'a'prints as.'a'(t27c gen-zig drops needed parentheses: (if ..) + 1 and -(x - y) #6329)ExprCall(value ignored) statement: a new refusal forf(x);with a non-voidfin a bodyzig testanalyzes.specs/fpga/bpsk.t27is BLOCKED in the reference. Without the refusal, t27b would have passed that file once its negative literals lowered.fn bench_<name>() void, so Zig never analyzes it. Without that change, the refusal blocked 9 reference-passing testbench files.Corpus (
t27b corpus specs --blockers --reference t27c, master f25dbee, same t27c binary and reference cache both runs)Newly passing, each agreeing test for test with the reference:
specs/fpga/testbench/axi4_tb.t27(reference BLOCKED) changed from timeout to rejected. No file regressed.Tests
switch_runs_only_the_taken_prong: verdicts equalt27c test-report.taken_prong_trapsfails on thex - 10overflow.discarded_call_result_is_refused_where_reached: a droppedu32in an uncalled fn, a bench, or a fn only a bench names passes. In a test it is BLOCKED, as in the reference.enum_rejections_are_precise, the old "switch is unsupported" case now checksExprSwitch(unreachable else).Reference quirks seen (not fixed here)
const w: u16 = 1000;as the literal1000, so Zig peer-types aniforswitchwith au8arm tou8and refuses the value. The reference is BLOCKED where t27b passes. This is pre-existing forifand not counted.switch(for examplespecs/.../json.t27, reference BLOCKED) is not lowered.🤖 Generated with Claude Code