Repository navigation
fix(builtins): invalid-identifier compound operands report plain word; declare 'a[]=x' reports bare bad array subscript (Refs #3186) - #3464
Conversation
…ipt diagnostic (#3186) Refs-only: regression nail first, fix to follow. GNU anchors: builtins/setattr.def valid_identifier (sh_invalidid, builtins/common.c:208); builtins/declare.def:613 valid_array_reference/valid_identifier; arrayfunc.c:359 assign_array_element sublen<=1 -> err_badarraysub (error.c:440-443); parse.y:5648-5657 token_is_assignment + subst.c:12949 expand_declaration_argument (W_COMPASSIGN only for valid-identifier LHS). UNVERIFIED-BY-CAPTAIN
…; declare 'a[]=x' reports bare bad array subscript (#3186) GNU anchors: builtins/setattr.def valid_identifier (sh_invalidid, builtins/common.c:208); builtins/declare.def:613; arrayfunc.c:359 assign_array_element sublen<=1 -> err_badarraysub (error.c:440-443); parse.y:5648-5657 token_is_assignment + subst.c:12949 expand_declaration_argument (W_COMPASSIGN only for valid-identifier LHS); general.c:288 valid_identifier (letter/_ first). - executor/declare_local.rs: the -a/-A hint arms of the is_compound gate now require a strictly valid identifier LHS base, so an invalid compound operand takes the plain word path and the builtin's InvalidId diagnostic quotes the plain expanded word (double-quoted $x expands, single-quoted text stays verbatim) instead of the marker/quoted compound expansion. - parser/token_actions.rs: valid_compound_assignment_lhs now requires an ASCII-letter/_ first character, so unquoted 9bad=(x) is no longer marked a compound assignment and reports builtin InvalidId. - builtins/declare.rs: an assignment to an empty subscript (declare 'a[]=x', also -a/-A, +=, typeset, local-in-function) reports the bare 'a[]: bad array subscript'; -p stays 'not found', no-assignment 'a[]' and export/readonly 'a[]=x' stay InvalidId. Known residual: GNU also creates the empty array (declare -a a=()) after the bad-subscript failure; this change repairs the diagnostic only. Unquoted 9bad=(x) is a GNU parse-time syntax error; rubash reports builtin InvalidId (same rc=1), locked by the nail pending a captain ruling. UNVERIFIED-BY-CAPTAIN
cargo fmt --check flagged 10 hunks in tests/issue3186_readonly_export_invalid_ident_compound.rs; formatting only, no semantic change. Refs #3186. UNVERIFIED-BY-CAPTAIN
复核结论:FAIL(1 项返工,钉子本身;产品修法已验证通过)产品修法在 Linux 与 Windows 双侧都已验证正确;钉子在 Windows 上不通过—— 返工项(唯一)
钉双边(按测试名)
三方探针(GNU 5.3.20 oracle,27 形 s01–s27)
lib 双边(Windows,bin 先建)
|
Rework of PR #3464 per captain review FAIL: the pin's run_script normalize only replaced the Rust-side native spelling (C:\...), which never matches the translated paths rubash prints on Windows (stderr /c/Users/..., stdout C:/Users/...). path_variants now covers native + forward-slash + /c/... + /C/... spellings, script path first (it contains the scratch dir as a prefix). Diagnostic-text expectations untouched. On unix path_variants returns only the native spelling, so Linux behavior is unchanged. Windows head pin 22/22, base fail-first 5 passed / 17 failed with the 17 names matching the review dossier §4.2 exactly; rustfmt clean.
复核结论:PASS(聚焦重审,第 13 轮,新头 5b5ee0f)FAIL 的唯一项——钉子 合入:先 update-branch(与活尖交集非空但 hunk 不重叠),再做合并形重验(钉 22/22 + lib 双边名集 ∅ + |
…yntax error (Refs #3495) (#3862) * fix(lexer): unquoted digit-leading compound LHS is a GNU parse-time syntax 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 * style(tests): rustfmt issue3495 digit-compound parse-error pins (Refs #3495) --------- Co-authored-by: 曹梦轩 <[email protected]> Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Refs-only draft PR for rubash #3186 (bug, P3-low). UNVERIFIED-BY-CAPTAIN.
根因
Executor::rewrite_declare_operand_subscripts(src/executor/declare_local.rs:520) 的is_compound门在-a/-A提示臂不查 LHS 合法性:无效名复合操作数也被当复合展开(字段打 \x10 + 元素加合成引号),随后内建 InvalidId 诊断直接引用带标记词。valid_compound_assignment_lhs(src/parser/token_actions.rs:1762) 偏松:只要求全 alnum/_ 且含字母,不要求首字符为字母/_,故9bad被当合法复合 LHS 标记。declare 'a[]=x'走 InvalidId 分支,未按 GNU 报裸a[]: bad array subscript。GNU 锚点
builtins/setattr.defvalid_identifier 检查 +builtins/common.c:208 sh_invalidid(\X': not a valid identifier);builtins/declare.def:613`(offset==0 先 valid_array_reference 再 valid_identifier;offset!=0 时 assignment() 已校验下标)。arrayfunc.c:359assign_array_element sublen<=1 -> err_badarraysub(error.c:440-443,裸诊断)。parse.y:5648-5657token_is_assignment +subst.c:12949expand_declaration_argument:W_COMPASSIGN 只授给有效标识符 LHS。declare 'a[]=x'(含 -a/-A、+=、typeset、函数内 local)均为裸a[]: bad array subscript、rc=1、后继操作数继续绑定;declare 'a[]'(无 =)、declare -p 'a[]=x'、export/readonlya[]=x各守其原诊断。修复(3 处,均不在护栏文件面)
src/executor/declare_local.rsis_compound门:提示臂加 LHS 合法条件(严格 valid_identifier)。src/parser/token_actions.rs:1762收紧:首字符须 ASCII 字母或_。src/builtins/declare.rs验证环:base[]空下标赋值形改报裸a[]: bad array subscript(-p 面仍走 not found)。本 PR 删除了什么
未删除任何公开 API、内建、测试或文档。仅收紧两处判定谓词并改一处诊断分支;钉文件为新增。
已知残差(待队长裁)
declare -a 9bad=(x):GNU 为解析期 syntax error,修后为内建 InvalidId(同 rc=1、信息不同);钉锁定 InvalidId interim 行为。declare 'a[]=x'报错后仍创建空数组(declare -a a=());本修只修诊断,不建数组。验证(待补)
钉双边、三方探针、相邻茎、lib 双边、
RUSTFLAGS="-D warnings"全靶、hygiene + rustfmt、终头 CI 读数见 REPORT(~/workspace/fix-3186/REPORT.md,不入仓)。