Repository navigation
interpreter: create an array element when it is referenced - #146
Merged
Alonely0 merged 1 commit intoOct 26, 2026
Merged
Conversation
Reading a[k] for a missing key returned an uninitialized value without adding k, so 'x[1]; print length(x), (1 in x)' printed '0 0'. POSIX awk and gawk create the element on reference.
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.
|
GNU awk testsuite comparison: |
Alonely0
approved these changes
Oct 26, 2026
Alonely0
left a comment
Collaborator
There was a problem hiding this comment.
huh, I was under the impression this was already the case. Good catch, thanks for your contribution!
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.
POSIX awk: "a reference to a nonexistent element shall create that element", uninitialized. Here reading
a[k]for a missing key returns an uninitialized value and doesn't addk:Scripts that rely on it, such as
{ seen[$1] } END { for (k in seen) ... }or a guard likeif (a[k] == "")followed bylength(a), see an empty array.(k in a)still doesn't create anything.get_array_elem(used byIndexS) now inserts an uninitialized value withentry_ref(..).or_insert_with(Value::new_untyped), the wayarray_elem_aoaalready does for arrays of arrays.Test
test_referencing_an_element_creates_it(fails on main).cargo test --workspace: 219 pass (218 on main), clippy clean. Eight programs around element reads,in, counting and assignment give the same output as gawk 5.3.2.