Repository navigation
Fix #1295 (char/byte literal match pattern) and #1299 (named struct pattern in let) - #1312
Merged
Merged
Conversation
added 2 commits
September 22, 2026 11:12
§22 makes a char/byte literal an integer literal value and §29 lists
CHAR_LIT under LITERAL_PAT, but parse_pattern only knew TK_INT_LIT and
is_arm_token (the match-arm start predicate) did not list TK_CHAR_LIT, so
the arm list ended silently before `'{' =>` and the line fell through to
the statement parser ("expected expression" at `=>`).
- char_literal_value(text) is the one decoder for 'X' / b'X' and its
escapes; parse_char_literal and the pattern parser both call it.
- parse_pattern treats TK_CHAR_LIT like TK_INT_LIT: bare (NK_PAT_INT) and
as either endpoint of a range ('a'..='z', b'0'..=b'9').
- is_arm_token and the for/parameter pattern-start predicates admit
TK_CHAR_LIT.
test/behavior/behav_match_char_literal_pattern.w covers bare, escaped,
ranged and constructor-nested (Some(b'{')) forms.
`let Req { name, email } = req` failed with "let binding requires
initializer": parse_let_binding routed a destructuring let only when
the pattern began with (, { or [, so an uppercase name followed by {
fell into the plain-binding path, which then found no `=`. §29's
STRUCT_PAT is `[ TYPE ] '{' ... '}'` and §9.7 says every pattern form
is available in let.
An uppercase name followed by `{` now builds the pattern with
parse_struct_pattern — the same NK_PAT_STRUCT node a match arm builds,
so Sema's Drop gate (#1291) and MirLower see one form — and the
`= value [else: body]` tail is shared with the anonymous forms via
parse_let_pattern_rest.
Tests: behav_let_named_struct_pattern.w (by value on a non-Drop struct,
view bindings over &req, rename, .., nested named patterns);
err_drop_destructure_let_named.w (the named form is refused on a Drop
type with the same fix-it as the anonymous form).
ehartford
added a commit
that referenced
this pull request
Sep 22, 2026
…mpiler defects (#1338) * examples: ephemerality-and-lowering stores the element directly, store(order[2], ...) (#1287 fixed in #1311) The typed-binding detour around #1287 (Atomic intrinsics passed an element view's address as the value) is gone with its comment. Package test output unchanged on a release compiler built from ae609cd. * examples: json-parser matches byte literals as patterns and returns &entry.value inline (#1295, #1297 fixed) Byte arms are Some(b'{') patterns, not guards (#1295, fixed in #1312); json_get_field returns Some(&entry.value) from a for loop over the entries, and the kv_value helper is gone (#1297, fixed in #1327). Workaround comments removed. Demo and package test output unchanged on a release compiler built from ae609cd. * examples: nebula's Status and Telemetry carry @[derive(Debug, Clone)] again (§11.8; #1288, #1289 fixed in #1311) The parking comment is removed. Demo and package test output unchanged on a release compiler built from ae609cd. * examples: service builds its change list and SET clause with the §7.2 builder (#1298 fixed in #1319) describe_changes and PgUserRepo.update spell with Vec.new() as mut ...: with a trailing if; the var desugaring and its comments are gone. Demo and package test output unchanged on a release compiler built from ae609cd (neither function is reached by the demo; the same shape was run separately under --debug-alloc: correct result, zero leaks). * examples: ecs cites D43 for DenseStorage.insert's -> Unit, not #1296 insert's tail if has an assignment arm (a value of type T) and a push arm (Unit): two meanings remain, so -> Unit is the spelling D43 requires, not a workaround. The compiler currently infers Unit without it because the assignment arm is a multi-statement block (#1337); the one-statement spellings of the same arm are rejected as D43 requires. --------- Co-authored-by: Eric Hartford <[email protected]>
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.
Fixes #1295. Fixes #1299.
Two parser defects found by the #1150 examples rewrite, one commit each.
#1295: a char or byte literal is a match pattern
§22 makes
'X'/b'X'an integer literal value and §29 listsCHAR_LITunderLITERAL_PAT, butparse_patternonly knewTK_INT_LIT, andis_arm_token(the match-arm start predicate) did not listTK_CHAR_LIT, so the arm list ended silently before'{' =>and the line fell through to the statement parser ("expected expression" at=>).char_literal_value(text)is now the one decoder for'X'/b'X'and their escapes;parse_char_literaland the pattern parser both call it (the byte-chainesc == 110 ...is gone).parse_patterntreatsTK_CHAR_LITlikeTK_INT_LIT: bare (NK_PAT_INT) and as either endpoint of a range ('a'..='z',b'0'..=b'9').is_arm_tokenand thefor/parameter pattern-start predicates admitTK_CHAR_LIT.#1299: a named struct pattern parses in
letlet Req { name, email } = reqhit "let binding requires initializer":parse_let_bindingrouted a destructuring let only when the pattern began with(,{or[, so an uppercase name followed by{fell into the plain-binding path.STRUCT_PAT := [ TYPE ] '{' ... '}'(§29); "all pattern forms are available in let" (§9.7).An uppercase name followed by
{now builds the pattern withparse_struct_pattern— the sameNK_PAT_STRUCTnode amatcharm builds, so Sema's Drop gate (#1291) and MirLower see one form — and the= value [else: body]tail is shared with the anonymous forms viaparse_let_pattern_rest.Tests
test/behavior/behav_match_char_literal_pattern.w: bare, escaped, ranged and constructor-nested (Some(b'{')) char/byte patterns.test/behavior/behav_let_named_struct_pattern.w: by value on a non-Drop struct, view bindings over&req, rename,.., nested named patterns.test/compile_errors/err_drop_destructure_let_named.w: the named form is refused on a Drop type with the same fix-it as the anonymous form (Sema: a pattern never skips a destructor — destructuring a Drop value errors outside the type's own move fn, total inside it (#1272) #1291).Verification (iterate tier)
with check src/main.wok;WITH=$PWD/src/main src/main build :devgreen from the committed HEAD; the three new tests plus all oftest/spec/spec_ss09_*,test/behavior/behav_*pattern*,behav_*match*,behav_drop_destructure_rule.wandtest/compile_errors/err_drop_destructure_*pass under stage1 (34 files). The twopre_d_build_runnertests the*match*glob also catches (behav_capability_token_mismatch.w,behav_file_prefix_map_objects_match.w) need anout/stageorout/releasecompiler that a:dev-only worktree does not have; the former passes on the untouched main tree. Battery not run: the branch waits for the batch.