Skip to content

Postfix ++ and -- on an array element (4.2.24) - #779

Merged
ddehilster merged 1 commit into
masterfrom
fix/postfix-index-inc
Oct 14, 2026
Merged

ddehilster merged 1 commit into
masterfrom
fix/postfix-index-inc

Conversation

@ddehilster

Copy link
Copy Markdown
Member

Bug. x[i]++ and x[i]-- ignored the index. They looked at the whole variable, saw several values, and failed with "Can't increment multi-valued variable", while the prefix form ++x[i] worked. The interpreter and compiled analyzers both had this gap. I found it while testing #778.

Fix. The indexed element is now changed, and its old value is returned, as postfix should. An index past the end pads with zeros, the same as assigning to x[i].

  • Shared helpers: Arun::index_arg (find or pad the element) and Arun::bump_arg (±1 on a number or numeric string).
  • Interpreted: the POSTUNARY case in Iexpr uses them.
  • Compiled: Arun::postinc/postdec use them too. They also gain RFASem*-index overloads, so an index expression such as L("x")[L("i")]++ compiles. Prefix inc/dec already had these overloads.

Testing

  • New fixture tests/postfix-index, with CI steps for Windows and Linux. It covers the returned value, the element changed, padding past the end, a numeric string, an expression index on a local array, a node variable's array, and plain scalars (unchanged). On 4.2.18 the same fixture produces no output and 5 errors.
  • I also built the fixture as a compiled analyzer DLL; its output is identical to the interpreted run.
  • All 40 Windows CI fixture steps pass locally, and the -DEV Full English Test output is unchanged.
  • All 20 analyzers in analyzers/ (21 inputs) produce byte-identical output to 4.2.18.

🤖 Generated with Claude Code

x[i]++ and x[i]-- ignored the index: they looked at the whole variable, saw
several values, and failed with "Can't increment multi-valued variable", while
prefix ++x[i] worked. Both runtimes had the same gap.

Now the indexed element is changed (padding with zeros past the end, as
assigning to x[i] does) and its old value is returned. Shared helpers
Arun::index_arg and Arun::bump_arg serve the interpreted POSTUNARY case and the
compiled Arun::postinc/postdec, which also gain RFASem*-index overloads so an
index expression like L("x")[L("i")]++ compiles.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ddehilster
ddehilster merged commit d260369 into master Oct 14, 2026
7 checks passed
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