Skip to content

fix(lexer): unquoted digit-leading compound LHS is a GNU parse-time syntax error (Refs #3495) - #3862

Merged
caomengxuan666 merged 2 commits into
masterfrom
fix/3495-digit-compound-parse-error
Nov 17, 2026
Merged

caomengxuan666 merged 2 commits into
masterfrom
fix/3495-digit-compound-parse-error

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Refs #3495 (follow-up of the PR #3464 review, Refs #3186).

Root cause

declare -a 9bad=(x): GNU is a parse-time syntax error (syntax error near unexpected token '(', rc=2, whole script dies); rubash reported a builtin diagnostic (declare: '9bad=(x)': not a valid identifier, rc=1, script continues).

GNU gates the =( compound branch on token_is_assignment (parse.y:5653 -> parse.y:5270 -> general.c:480 assignment()), which requires a legal-variable-starter first character (general.c:498-502). The lexer's compound_assignment_start (src/lexer/word.rs) used a weaker all-alnum-plus-any-alpha test, so it folded 9bad=(x) into one atomic word and the declare builtin saw it as a flat operand. The two sibling validators — classification::is_assignment and token_actions::valid_compound_assignment_lhs — already enforced the starter rule since #3464; the lexer fold was the only decision point that did not.

Fix

One predicate in compound_assignment_start: require the first byte to be an ASCII letter or _. The word now ends at 9bad=, the ( reaches the parser as a stray token, and the existing stray-( arm reports the GNU error (rc 2, whole script dies). No parser or builtin change was needed.

Nail disposition

The #3464 nail declare_a_digit_leading_compound_unquoted_is_invalid_id explicitly locked the InvalidId interim (rc=1). It is updated in place (renamed to ..._is_parse_error) to expect the parse-time error, and the file header records the resolution. New stem tests/issue3495_digit_compound_parse_error.rs (21 tests) nails the class — declare/typeset/export/readonly/local, +=, subscript, bare 9bad=(x) (names x, parse.y:1054 function-head shift), echo argument, if-wrapped, eval containment — plus the guards that must not change: quoted '9bad=(x)' and paren-less 9bad=x stay InvalidId (rc=1), valid a9=/_9= compounds still bind.

本 PR 删除了什么

Nothing. No code, test, file, or behaviour is removed; the #3464 nail is retargeted (same test, new expectation), not deleted.

Verification (honest status)

  • GNU oracle: bash 5.3.20 (vendored tree binary), 20 script-file probes covering the class and the guards — all cited expectations byte-verified.
  • rubash build/test: NOT RUN — build chain down this round. X299-2607 unreachable (reverse tunnel down: server-side ssh -p 2666 → Connection refused; only the user can relaunch it on the PC). Simular box dead (wallet empty). Local build banned (no toolchain on this VM, MemAvailable ~0.5G). New-server hop 1 was restored this round (VM replacement had wiped /root/.ssh/; config + known_hosts recreated, host key fingerprint re-verified against the recorded SHA256). Old-server direct route needs the box-held key and is not usable from here.
  • cargo fmt --check not run (no toolchain on this VM); the pre-commit hook skips cleanly in that case. Formatting follows the surrounding style; re-check on the build machine.
  • Codegraph: compound_assignment_start has exactly one caller (skip_word_inner); impact set is the word scanner only.

UNVERIFIED-BY-CAPTAIN

caomengxuan666 and others added 2 commits November 17, 2026 15:42
…yntax error (Refs #3495)

GNU anchors: parse.y:5653 (compound branch gated on token_is_assignment)
-> parse.y:5270 token_is_assignment -> general.c:480 assignment() with the
legal_variable_starter gate (general.c:498-502); parse.y:1054 function-head
'(' shift names the next token for a bare '9bad=(x)'.

- lexer/word.rs: compound_assignment_start now requires an ASCII-letter/'_'
  first character, matching classification::is_assignment and
  token_actions::valid_compound_assignment_lhs (both already enforced it
  since #3464). '9bad=(x)' no longer folds into one word: the word ends at
  '9bad=' and the parser's stray-'(' arm reports 'syntax error near
  unexpected token `('`', rc 2, whole script dies.
- test: the #3464 nail that locked the InvalidId interim now expects the
  parse error; new tests/issue3495_digit_compound_parse_error.rs nails the
  class (declare/typeset/export/readonly/local, '+=', subscript, bare,
  echo-arg, eval containment) and the guards (quoted, paren-less scalar,
  valid names still bind).

UNVERIFIED-BY-CAPTAIN
@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 17, 2026 16:21
@caomengxuan666
caomengxuan666 merged commit 59d1c2b into master Nov 17, 2026
8 of 12 checks passed
@caomengxuan666

Copy link
Copy Markdown
Member Author

#3862 判词=PASS merge=59d1c2b4e lexer首字符门对齐GNU assignment(),20/20钉绿+GNU逐字节一致

head: 928cb4a(审计基座 9f909d6 + 本 lane rustfmt 提交 928cb4a,仅换行)base(merge-base): 3d8c9ff 文件: 3 个 +361/-7→合并后净 +354/-7
关联 issue: #3495(open→已关)

机制核查:

  • GNU 链路属实:parse.y:5653 复合 =( 分支由 token_is_assignment 把关 → parse.y:5270 token_is_assignment 拼 name= → general.c:480 assignment() → general.c:498/500 legal_variable_starter(general.h:117 sh_syntaxtab[c] & CNAMESTART,ASCII 域=字母+_)。数字起头 LHS 返回 0 → ( 落成游离 token → parse.y:1054/语法错误臂报 syntax error near unexpected token。
  • 修复点正确:compound_assignment_start(src/lexer/word.rs:839)首字节要求 ASCII 字母/_,与 classification::is_assignment(classification.rs:24)和 token_actions::valid_compound_assignment_lhs(token_actions.rs:1794)已有不变量一致;无 continuation.rs、无桥接层。
  • diff 无无关面;PR 正文与实际 diff 一致(声明的"未跑构建"已由本 lane 补齐)。

腿:

  • 钉自跑:issue3495_digit_compound_parse_error 20/20;issue3186_readonly_export_invalid_ident_compound 22/22(head 9f909d6 与 fmt 后 928cb4a 均绿)。
  • fail-first(base 3d8c9ff + 原样钉):issue3495 7p/13f,红名=13 个解析错误断言(其余 7 个守卫钉基线上本就该绿);issue3186 21p/1f,红名={declare_a_digit_leading_compound_unquoted_is_parse_error},与 PR 声称一致。
  • lib 双边:head {issue2084_session_end_restores_host_process_state(基线同红), issue863_gap8_finish_trap_runs_once_across_entries(全量并行下偶发,隔离重跑 6/6 绿,与本 diff 无语义交集)} / base {issue2084} / 净差=∅(issue863 判 flaky)。
  • -D warnings:lib + 本 PR 两钉 0 警告;--all-targets 另有 issue3814/issue3806 两处既有 dead_code(未触文件,基线)。
  • 卫生:rustfmt 本 PR 三文件曾有 3 处换行漂移→已由 928cb4a 修复,现 FMT_CLEAN;marker-lint OK;utf8-boundary clean。
  • CI:head 9f909d6 两红任务 GNU regression goldens and canaries / Regression pin stem census —— master 尖 41279ae 同名任务同红=基线;本 PR 全部 20+22 钉在 Linux CI 上 PASS。
  • GNU 对照:WSL /usr/local/bin/bash = GNU bash 5.3.20(1)-release;scratch-k2/ 20 例(钉全类+守卫)→ 20/20 逐字节一致(stdout+stderr+rc,cmp 全等)。

F 点:无。

续作记录:

  • 928cb4a style(tests): rustfmt issue3495 钉(仅换行);新 head 已推送并经 gh 复核。

未跑/VOID 的腿:无。

备注:PR 正文称钉 "21 tests",实为 20 个 #[test](已合入,不改判)。

@caomengxuan666

Copy link
Copy Markdown
Member Author

【k2 批次汇总】本波分工:#3862 审计 + #3835 接手核查

阻塞项:无。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant