Skip to content

fix: materialize local arrays and hashes before return#386

Merged
fglock merged 1 commit into
masterfrom
fix/local-array-return
Mar 27, 2026
Merged

fix: materialize local arrays and hashes before return#386
fglock merged 1 commit into
masterfrom
fix/local-array-return

Conversation

@fglock
Copy link
Copy Markdown
Owner

@fglock fglock commented Mar 27, 2026

Summary

When returning localized arrays or hashes from subroutines, the values must be copied before local restoration occurs. Without this fix, returning local @ARGV would return ARRAY references to the restored (original) values instead of the localized values.

  • Extended materializeSpecialVarsInResult() to copy RuntimeArray and RuntimeHash elements before local restoration happens
  • Added regression tests for returning local arrays and hashes from subroutines

Problem

sub args {
    local @ARGV = @ARGV;
    @ARGV = ('modified');
    return @ARGV;
}
my @result = args();
# Before fix: @result was empty (restored original)
# After fix: @result is ('modified')

This was blocking Module::Build test suite where the args() method uses this pattern.

Test plan

  • Unit tests pass (make test)
  • New regression tests added in local.t
  • Module::Build t/basic.t improved from 5 failures to 1 failure

Generated with Devin

When returning localized arrays or hashes from subroutines, the values
must be copied before local restoration occurs. Without this fix, returning
`local @ARGV` would return ARRAY references to the restored (original)
values instead of the localized values.

Extended materializeSpecialVarsInResult() to copy RuntimeArray and
RuntimeHash elements before local restoration happens.

Fixes Module::Build test failures where args() method returned ARGV
references to restored values.

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

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@fglock fglock merged commit 7d66f5c into master Mar 27, 2026
2 checks passed
@fglock fglock deleted the fix/local-array-return branch March 27, 2026 14:45
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