Repository navigation
Postfix ++ and -- on an array element (4.2.24) - #779
Merged
Merged
Conversation
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>
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.
Bug.
x[i]++andx[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].Arun::index_arg(find or pad the element) andArun::bump_arg(±1 on a number or numeric string).POSTUNARYcase inIexpruses them.Arun::postinc/postdecuse them too. They also gainRFASem*-index overloads, so an index expression such asL("x")[L("i")]++compiles. Prefixinc/decalready had these overloads.Testing
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.-DEVFull English Test output is unchanged.analyzers/(21 inputs) produce byte-identical output to 4.2.18.🤖 Generated with Claude Code