Repository navigation
fix(gen-c): a _ switch arm is the catch-all, not (x == _) (Closes #7428) - #7456
Merged
Merged
Conversation
gen-c lowers a switch to a chain of ternaries ending in the else value. The arm `_ =>` is the same catch-all and was written as the comparison `(x == _)`, which C rejects. The test in backend_behaviour.rs compiles and runs the C for an integer and an enum switch. Part of #5980. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Only gen_hash_c moves: the `== _` arms become the catch-all value. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
gHashTag
enabled auto-merge (squash)
October 7, 2026 10:06
This was referenced Oct 7, 2026
Merged
Merged
t27c: refuse a malformed number literal by name, read 0o as octal (Closes #7319, Closes #2645)
#7421
Draft
Closed
Contributor
This was referenced Oct 7, 2026
Closed
gHashTag
added a commit
that referenced
this pull request
Oct 8, 2026
…w lowers it as the catch-all (Closes #7879) (#7880) #7331 dropped the switch fixture's `_ =>` arm (43dbe54) because gen-c then wrote `(x == _)` for it, which C cannot compile. #7456 made `_` the catch-all, so `rest()` and its two asserts come back unchanged and the `_` catch-all is built and run, not only accepted. On the t27c lab (master ce605a6 with #7436): gen-c of the fixture has no `(x == _)`, and `cargo test --release -p t27c --test core_selfhost` passes 1/1. Co-authored-by: Claude <claude@anthropic.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
5 tasks
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 #7428
Part of #5980
What was wrong
gen-c lowers a switch expression to a chain of ternaries, and the
elsearm becomes the value at the end of the chain._ =>is the same catch-all, but gen-c wrote it as the comparison(x == _). C rejects that:'_' undeclared.The fix
bootstrap/src/compiler.rs: an arm named_is treated likeelse(+4/-1).Test
bootstrap/tests/backend_behaviour.rs, new testc_takes_the_underscore_arm_of_a_switch(+15). It generates C for an integer switch and an enum switch, compiles it with cc, runs it, and checks the output10 99 1 7.Run on the t27c lab with
try.sh, both ways:backend_behaviour23 passedcompiler.rsandFROZEN_HASHreverted to master: 22 passed, 1 failed (this test; cc refuses the C)Reseals
The corpus gen-c diff, old binary vs new over every spec under
specs/plus the 28 sealed specs outside it, changes exactly one file:specs/demos/jones_topology_decision_gate.t27. Its== _arms become the catch-all value. That spec is resealed, together with its twin seal:JonesTopologyDecisionGate.jsonanddemos_JonesTopologyDecisionGate.json. Onlygen_hash_c(db1eb4ba -> f692906e) and the bookkeeping fields move. No other seal goes stale.Budget
check_budget()from master (#7371) passes: compiler.rs +4, backend_behaviour.rs +15, 19 in total. Both files are already listed intools/policy/foreign-exceptions.txton master, so this PR does not touch that file.🤖 Generated with Claude Code