Repository navigation
fix5 statelife2: scalar-cell bad subscript (#1555) + array tempenv scalar shadow (#1556) - #1570
Merged
Merged
Conversation
…script) (rubash#1555)
GNU arrayfunc.c:1483 array_value_internal rebases a negative
subscript (array_max_index + 1 + ind) only when array_p(var); a
scalar cell (subst.c get_var_and_type VT_VARIABLE) never rebases,
so every negative subscript is INDEX_ERROR (arrayfunc.c:1462,
err_badarraysub) and the read is empty/unset. The rule is general
(measured on GNU 5.3.20 for plain scalars, unset and valueless
names alike); a scalar PIPESTATUS cell — observable inside a
tempenv window or as a function-local shadow, since a standalone
PIPESTATUS=99 command's own completion write reinstalls the live
array — fell back to a dense view and returned the value.
- public_accessors: pipestatus_element/pipestatus_subscript_resolves
no longer dense-fallback for non-LiveArray shapes; Scalar reads
element 0 from the mirror, negatives never resolve.
- arrays/executor: the element fetcher's scalar leg now owns the
diagnostic (GNU reports inside the fetch, so the operator,
pattern and substring arms see it too); expand_braced_ops drops
its duplicate report for the plain form.
- expand_braced_indices: ${#...} adjudicates via
array_length_reference (subst.c:7488) — absent/invisible bases
return 0 silently, scalar bases take the bracketed
bad-subscript failure, and PIPESTATUS lengths read the cell
instead of the empty env mirror.
- arithmetic: indexed reads no longer dense-rebase a non-array
base and report ArithEvalDiag::BadSubscript; the dynamic
context snapshots the scalar PIPESTATUS shape.
Regression: tests/issue1555_scalar_subscript_bad_subscript_regressions.rs
(12 tests, GNU 5.3.20 expectations).
…sh#1556) GNU variables.c:3536 assign_in_env (from subst.c:13142 do_assignment_statements) creates every temporary-environment binding as a fresh scalar in the separate temporary_env table (make_new_variable + var_setvalue, att_exported|att_tempvar only); the outer cell is never written. rubash routed a plain bind over an array name through the permanent bind, which wrote the value into element 0 in place: window reads saw a mutated array (declare -ax a=([0]="99" [1]="9")) instead of the shadow scalar, and assoc windows grew a bogus [0] key. - apply_temporary_assignments: when the effective target's cell is an array (attribute word or typed cell), swap in the tempvar shadow directly — scalar typed cell + mirror text + fresh exported-only VarAttrs; the per-name snapshot reinstalls cell, mirror and attrs at restore. Append computes against the old cell's scalar view (make_variable_value ASS_APPEND: element 0 for indexed, empty for assoc). A readonly target reports with the plain error prefix and drops the word without the export-mark leak the fallthrough tail produced. Dynamic stack arrays (FUNCNAME/BASH_ARGV/...) keep the old path; PIPESTATUS keeps its #1525 branch. - The compound tempenv branch now also resets the window attrs to the fresh tempvar word (it already bound the literal scalar text; the surviving array marks kept declare -p rendering it as an array). - strip_invalid_env_assignment_prefixes: simple assignment words following a stripped array-style word move into the assignment list (the parser's classification stops at the array-style word, so a[0]=5 b=2 declare -p b dispatched b=2 as the command name); GNU assign_in_env skips the invalid word and binds the rest. Regression: tests/issue1556_array_tempenv_window_regressions.rs (13 tests, GNU 5.3.20 expectations).
Member
Author
集成树门控复验(master
|
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 #1555
Fixes #1556
第五波 statelife2 簇集成片:两条 PIPESTATUS/tempenv 残余修复,各一个 commit,自 statelife2 簇分支按序拣入当前 master(零冲突)。
#1555 — 标量格负下标报
bad array subscriptGNU 的是一般规则(
arrayfunc.c:1483 array_value_internal):负下标 rebase(array_max_index + 1 + ind)仅当array_p(var);标量格(VT_VARIABLE)永不 rebase,仍 <0 即 INDEX_ERROR → 打印NAME: bad array subscript、读空。该检查在var==0/无值格早退之前,故未 set、declare 无值的名字负下标同样报错;真数组负下标相对末尾(保持)。修复按同一规则的四个入口对齐:
public_accessors.rs):pipestatus_element/pipestatus_subscript_resolves对非 LiveArray 形状不再 dense fallback;Scalar 仅 [0] 读镜像文本,负下标永不 resolve,既有诊断臂开火。arrays/executor.rs+expand_braced_ops.rs):元素 fetcher 的标量腿自持诊断(GNU 在 fetch 内报,故${v[-1]:-DEF}、${v[-1]#9}、${v[-1]:0:1}、非字面下标都报);ops 整数臂删重复打印防双报;负下标按 unset 参与-/:-/+判定。expand_braced_indices.rs):按subst.c:7488 array_length_reference重排——declare 无值 → 静默 0;标量基负下标 → 方括号诊断 + 整条命令丢弃;PIPESTATUS 长度改读 cell。arithmetic/value.rs+dynamic_arrays.rs):非数组基负下标不再 dense rebase,推ArithEvalDiag::BadSubscript;ArithDynamicContext 新增 PIPESTATUS 标量形状快照裁决。立项复现订正:issue 原文的
true | false; PIPESTATUS=99; echo "[${PIPESTATUS[-1]}]"在 GNU 上输出[0]——独立赋值命令自身的 completion 写回先把活数组装回,标量格在下一命令读不到。标量格可观测点只有 tempenv 窗口(PIPESTATUS=99 eval '...')与函数 local 影子(local PIPESTATUS=99),两处 GNU 均报错读空。bug 真实,复现形态按此修正,回归测试按可观测形态钉住。#1556 — 普通数组 tempenv 窗口应见标量影子
GNU 模型 =
variables.c:3536 assign_in_env:每个 tempenv 绑定都是在独立temporary_env表里新建的标量(仅 att_exported|att_tempvar),外层格从不写入;窗口读全见影子,处置后原状态天然完好。rubash 原状是把标量值就地写进数组格的元素 0,窗口读见被改的数组(declare -ax a=([0]="99" [1]="9")),assoc 还多出伪 [0] 键,只读拒绑后 -x 导出标记泄漏。修复(
temporary_assignments.rs,apply 循环内,#1525 的 PIPESTATUS 分支保持在前不动):previous快照整体还原;append 按旧格标量视图(索引取元素 0、assoc 取空)拼;只读目标走纯 error_prefix 诊断且不再打导出标记;动态栈数组显式排除、保持旧路。a=(7 8) declare -p a→declare -x a="(7 8)")。command_execute.rs):a[0]=5 b=2 declare -p b中数组式词之后的简单赋值词原被当命令名(b=2: command not found);现剥除后按 set -k harvest 形态移入 assignments(恒留一词作命令名)。验证账本(簇侧,集成树复验随后以评论补入)
src/lexer/continuation.rs、未动载体字节、[perf] "${a[@]}" iteration is O(n²): 40k elements take 516s (GNU 0.24s) #1510 freshness 面未触;改动文件 fmt 干净、CR 0。残余(已立项 / 已载明)
${!PIPESTATUS[@]}作为首次触碰报invalid indirect expansion、rc=1,master 既有。a[0]=5 b=2亦未覆盖。export -p列出 tempenv 绑定(标量路径 master 同病)。arithmetic syntax error(错误 token 为原始 \001 字节,系 GNU 自身 bug);rubash 给出 sane 影子,接受差异。${#v[$i]}(i=-1)GNU 报[$i]: bad array subscript并丢弃命令,rubash 现静默输出长度;Fix C 只覆盖字面整数下标臂。