Skip to content

fix: operator precedence in Stash.pm hash ops guard#342

Draft
Koan-Bot wants to merge 1 commit intoabw:masterfrom
atoomic:koan.atoomic/fix-stash-operator-precedence
Draft

fix: operator precedence in Stash.pm hash ops guard#342
Koan-Bot wants to merge 1 commit intoabw:masterfrom
atoomic:koan.atoomic/fix-stash-operator-precedence

Conversation

@Koan-Bot
Copy link
Contributor

@Koan-Bot Koan-Bot commented Mar 8, 2026

What

Adds explicit parentheses to fix operator precedence in lib/Template/Stash.pm:459.

Why

The condition && ! $atroot || $item eq 'import' is parsed as (&& !$atroot) || ($item eq 'import') due to && binding tighter than ||. This means the elsif branch could theoretically be entered for 'import' even if the $HASH_OPS lookup didn't assign $value — a latent bug that contradicts the comment's stated intent: "only allow import vmeth to be called on root stash".

How

Single character change: wrap ! $atroot || $item eq 'import' in parentheses → (! $atroot || $item eq 'import'). Added 2 tests for hash vmethod and import behavior on non-root hashes.

Testing

  • Full test suite: 2963 tests pass (107 files)
  • t/stash.t: 77/77 (2 new tests added)

🤖 Generated with Claude Code

The condition `&& ! $atroot || $item eq 'import'` was parsed by Perl
as `(&& ! $atroot) || ($item eq 'import')` due to && binding tighter
than ||. This meant the elsif branch could be entered for 'import'
regardless of whether $HASH_OPS lookup succeeded.

Add parentheses to match the comment's stated intent: allow HASH_OPS
virtual methods on non-root hashes, and only allow 'import' on root.

Also add tests for hash vmethods and import on non-root hashes.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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