Skip to content

Fix stash deletion not removing CODE refs properly#377

Merged
fglock merged 1 commit into
masterfrom
investigate/jcpan-moo-issues
Mar 25, 2026
Merged

Fix stash deletion not removing CODE refs properly#377
fglock merged 1 commit into
masterfrom
investigate/jcpan-moo-issues

Conversation

@fglock
Copy link
Copy Markdown
Owner

@fglock fglock commented Mar 25, 2026

Summary

This fixes a bug where delete ${"Foo::"}{bar} would not properly remove the stash entry when using the ${BLOCK}{key} syntax.

Root Causes Fixed

  1. JVM Backend (Dereference.java): The handleHashElementOperator method for ${BLOCK}{key} patterns always called hashDerefGet/hashDerefGetNonStrict regardless of whether the operation was "get", "delete", or "exists".

  2. Interpreter (CompileExistsDelete.java): The resolveHashFromBinaryOp method didn't compile operands in SCALAR context, causing -1 register errors when the operand was a BlockNode.

Test Case

package Foo;
sub bar { 42 }

no strict "refs";
print "Before: ", (exists ${"Foo::"}{bar} ? "yes" : "no"), "\n";  # yes
delete ${"Foo::"}{bar};
print "After: ", (exists ${"Foo::"}{bar} ? "yes" : "no"), "\n";   # no (was incorrectly "yes")

Note: Stash deletion removes the stash entry but compiled subroutine references continue to work (matching Perl's CV caching behavior).

Test plan

  • Both JVM and interpreter backends correctly return "no" after stash deletion
  • op/symbolcache.t passes with same results as master (5/8)
  • Build passes

Generated with Devin

This fixes a bug where delete ${\042Foo::\042}{bar} would not properly
remove the stash entry when using the ${BLOCK}{key} syntax.

Changes:
- JVM backend (Dereference.java): Fix handleHashElementOperator to use
  the hashOperation parameter for ${BLOCK}{key} patterns. Previously
  it always called hashDerefGet regardless of delete/exists operations.
- Interpreter (CompileExistsDelete.java): Fix resolveHashFromBinaryOp
  to compile operands in SCALAR context to avoid -1 register errors.

Note: Stash deletion removes the stash entry but compiled subroutine
references continue to work, matching Perl CV caching behavior.

Generated with [Devin](https://cli.devin.ai/docs)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@fglock fglock force-pushed the investigate/jcpan-moo-issues branch from 0f1682f to 55a7bad Compare March 25, 2026 14:03
@fglock fglock merged commit 884af98 into master Mar 25, 2026
2 checks passed
@fglock fglock deleted the investigate/jcpan-moo-issues branch March 25, 2026 15:54
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