Skip to content

fix(lexer): skip # comments in the alias pre-pass walkers (rubash#2033) - #2116

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/2033-modernish-use-2
Oct 29, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/2033-modernish-use-2

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Closes #2033. Tracking root-cause comment: #2033 (comment)

Root cause

Modernish use sys/cmd/harden killed initialization with
harden.mm: eval: line 163: syntax error near unexpected token 'fi'.

The alias-live gather's streaming alias expander pre-pass
(ComsubAliasScanner::drive, src/lexer/alias_stream.rs) and its batch
twin (expand_comsub_alias_bodies) walked their scan text with quote
arms but no # comment arm. An apostrophe inside a comment
("modernish's" in harden.mm line 4) opened a phantom single-quote string:

  • batch walker: the quote skip swallowed the rest of the input, hiding
    real $( units from alias expansion;
  • streaming walker: the unterminated quote PARKED the phase across whole
    input spans (rescan_park + retry_deadline span throttle); the gather
    (script_driver.rs read_next_source_group) then advanced its
    feeder/battery completeness machines in bursts instead of per line,
    their state diverged from the non-alias arm, and the verdict wrongly
    blessed a mid-function group cut (harden.mm lines 4..276 of 404). The
    cut chunk fails to parse standalone at the \esac mode table.

Trigger shape explained: without aliases the raw arm gathers the same
file correctly (expand_aliases + >=1 alias defined is the switch), and
whole-string eval was clean because the batch entry path parses the
full text with the comment-aware main scanner.

GNU anchor: parse.y:3631-3645 shell_getc — #' at a shell_getc position always comments until EOL; a mid-word #' never reaches shell_getc.
Class probed on WSL GNU Bash 5.3 (matrix in the issue comment).

Fix

Both pre-pass walkers gain an at_word_start token-boundary state (true
after input start / blank / newline / ; & | ( ) < >); # at a token
start skips to EOL inert. The streaming form parks only when the
comment's newline is not yet fed (mirroring MainAliasScanner's own #
arm). stream==batch preserved by construction.

Verification

  • tests/issue2033_alias_comsub_comment_park_regressions.rs: 3 tests;
    failing frames verified on the pre-fix binary, green here
  • modernish end-to-end: use sys/cmd/harden; type -t harden ->
    function, rc=0; multi-module + repeat-use smoke green
  • alias_stream streaming-contract unit tests 7/7
  • comment-class GNU matrix byte-identical except two pre-existing rows
    (identical on pristine; separate gaps)
  • true-baseline A/B, 19 suites: fixed ledger == pristine ledger

fmt note: cargo fmt fails with os error 206 in this environment;
rustfmt was run explicitly on both touched files (rustfmt --check
clean). Commit uses --no-verify for that environment reason only.

…033)

Modernish `use sys/cmd/harden` killed initialization with
`harden.mm: eval: line 163: syntax error near unexpected token 'fi'`.

Root cause: the alias-live gather's streaming alias expander pre-pass
(`ComsubAliasScanner::drive`) and its batch twin
(`expand_comsub_alias_bodies`) walked command-substitution-unit scan text
with quote arms but no `#` comment arm. An apostrophe inside a comment
("modernish's" in harden.mm line 4) opened a phantom single-quote string:
the batch walker's quote skip then swallowed the rest of the input
(hiding real `$(` units from expansion), and the streaming phase PARKED
on the unterminated quote across whole input spans (rescan_park +
retry_deadline span throttle). The alias-live gather
(script_driver.rs read_next_source_group) then advanced its feeder/battery
verdict machines in bursts instead of per line, their state diverged from
the non-alias arm, and the completeness verdict wrongly blessed a
mid-function group cut (harden.mm lines 4..276 of 404); the cut chunk
failed to parse standalone at the `\esac` mode table. Without aliases the
same file gathered correctly, which is why the trigger is
`expand_aliases` + >=1 alias defined.

GNU anchor (parse.y:3631-3645 shell_getc): `#' at a shell_getc position
ALWAYS comments ("Discard until EOL or EOF"); a mid-word `#' (echo a#b)
never reaches shell_getc because read_token_word consumes word characters
without returning to the character feeder. Probed on WSL GNU Bash 5.3:
`echo a#b` -> `a#b`; `echo >#f` -> syntax error (`#' after `>' IS a
comment); `$( # hi ' there <NL> echo IN )` -> IN (comment apostrophes
inert).

Fix: give both pre-pass walkers an `at_word_start` token-boundary state
(true after input start / blank / newline / ; & | ( ) < >) and skip
`#`-at-token-start comments to EOL inert; the streaming form parks only
when the comment's newline is not yet fed, mirroring MainAliasScanner's
own `#' arm. stream==batch is preserved by construction.

Verification:
- regression tests/issue2033_alias_comsub_comment_park_regressions.rs
  (3 tests; the sourced-hardem-module frame and the comsub-after-comment
  pin both FAIL on the pre-fix binary, pass on this build)
- modernish end-to-end: `use sys/cmd/harden; type -t harden` ->
  `function`, rc=0; multi-module `use` and repeat-`use` smoke green
- alias_stream streaming-contract unit tests 7/7
- comment-class GNU matrix (10 rows) byte-identical to GNU except two
  rows pre-existing identically on the pristine binary
- true-baseline A/B, 19 suites (alias case casemod comsub comsub2
  comsub-eof comsub-posix heredoc iquote nquote nquote1-5 quote
  quotearray redir vredir): fixed ledger == pristine ledger per suite

fmt: cargo fmt hits "os error 206" in this environment; rustfmt run
explicitly on both touched files (rustfmt --check clean), commit uses
--no-verify for that environment reason only.

Fixes: #2033
@caomengxuan666
caomengxuan666 merged commit 81d6005 into master Oct 29, 2026
11 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/2033-modernish-use-2 branch October 30, 2026 01:41
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.

modernish 套件启动期死于真实 use 加载上下文(harden.mm 级联误报,生态审计 DIV-F2)

1 participant