feat(t27b): lower char literals natively as comptime_int - #6331
Merged
Merged
Conversation
A char literal is one byte or a backslash plus one byte; t27c prints it verbatim and Zig types it as comptime_int, so t27b lowers it to an untyped integer constant. What Zig rejects is refused by name: ExprLiteral(char escape) for '\0', ExprLiteral(char byte) for a raw control byte, ExprBinary(char literal << >>) for a shift by a typed or runtime amount. Corpus with --reference: counted 601 -> 606 of 720, mismatch 0. Closes #6330 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
This was referenced Oct 5, 2026
6 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 #6330
Refs #6063
What
ExprLiteral(char literal)was first in the reference-backed greedy order (+5 files). The t27c lexer makes a char literal from one byte or a backslash plus one byte, the parser keeps the quotes, and gen-zig prints it verbatim, so Zig types it ascomptime_int; t27c's optimizer never folds or propagates it (is_literalreads integers only). t27b now lowers it to an untyped integer constant (Val::Ct).Refused by name, each checked against
t27c test-report(all three BLOCKED there):ExprLiteral(char escape):'\0'and escapes outside\n \r \t \\ \' \"(Zig: "invalid escape character").ExprLiteral(char byte): a raw control byte inside the quotes (Zig: "character literal contains invalid byte").ExprBinary(char literal << >>): a shift by a typed or runtime amount; t27c prints'a' << @intCast(k)(Zig: "unable to cast runtime value to 'comptime_int'").Test
char_literals_are_comptime_intsincli/t27b/tests/source.rs: undert27c test-reportthe same source givesdigits_and_casePASS,escapesPASS,overflow_trapsFAIL; t27b gives the same, with the overflow trap at line 21. The blockers fixture now uses'\0'as its unsupported literal.Corpus (
t27b corpus specs --blockers --reference <t27c from origin/master 634b3ff26>)Gained (reference pass, t27b pass): TbCheck_new, gen_w380, mcp-wrapper, railway_create_project, gen_color. The two new fails agree with the reference or have none:
specs/tri/search/pattern.t27failswildcard_match_no_matchin both, 10 other tests pass in both;specs/port/scripts/gen_w368.t27is BLOCKED in the reference (redeclaration of local variable 'k') and its t27b failure is the spec's own test logic (the second scan loop starts where the first ended).queen-lease.t27now passes in t27b but is BLOCKED in the reference ('_' used as an identifier), so it is not counted.Load average during the runs: 20-130 (local Mac).
docs/reports/t27b_expectations.jsonis not touched here: six of itsExprLiteral(char literal)rows will read as UNEXPECTED PASS or a new blocker; the steward re-blesses.Seen, not fixed here (t27c)
const X: u8 = 'a';loses its value: gen printsconst X: u8;(t27b already refuses it asConstDecl ... has no value)..'a' =>.🤖 Generated with Claude Code