Fix tied variables in void context not calling FETCH#335
Merged
Conversation
When accessing tied hash/array elements in void context (e.g., $hash{key};),
PerlOnJava was incorrectly optimizing out the access because the lazy proxy
(RuntimeTiedHashProxyEntry) was never read. This broke expected Perl semantics
where tied variable access should trigger FETCH regardless of context.
The fix adds handleVoidContextForTied() in EmitOperator.java which calls
getBoolean() to force FETCH before the value is discarded with POP. This is
applied to hash element ($hash{key}) and array element ($array[0]) operators.
Known limitation: eval { } blocks transform the block into sub { }->() at
parse time, so the last statement runs in scalar context instead of void.
This is documented but not fixed in this PR.
Generated with [Devin](https://cli.devin.ai/docs)
Co-Authored-By: Devin <noreply@cognition.ai>
The initial tied void context fix called getBoolean() on all hash/array element operations in void context. However, delete() can return null for sparse arrays, causing NullPointerException. Now only applies handleVoidContextForTied() for "get" operations. Delete and exists operations use the standard handleVoidContext() (plain POP). Also fixed slices to not double-pop in void context. Generated with [Devin](https://cli.devin.ai/docs) Co-Authored-By: Devin <noreply@cognition.ai>
In Perl, pop/shift/delete on sparse array elements should return undef, not Java null. ArrayList.removeLast()/removeFirst() returns null when the element at that position is null (sparse array). This was the root cause of the NullPointerException in the tied void context fix - delete() calls pop() for the last element. Generated with [Devin](https://cli.devin.ai/docs) Co-Authored-By: Devin <noreply@cognition.ai>
9b7408e to
eefceed
Compare
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.
Summary
Fixes #20 - Tied variables accessed in void context weren't calling FETCH.
Problem
When accessing tied hash/array elements in void context (e.g., $hash{key};), PerlOnJava was incorrectly optimizing out the access because:
Solution
Added handleVoidContextForTied() in EmitOperator.java that:
This is applied to hash element ($hash{key}) and array element ($array[0]) dereference operators.
Changes
Known Limitation
eval { } blocks are not covered by this fix because PerlOnJava transforms them into sub { }->() at parse time. This is documented in the test file.
Test plan
Generated with Devin