fix: operator precedence in Stash.pm hash ops guard#342
Draft
Koan-Bot wants to merge 1 commit intoabw:masterfrom
Draft
fix: operator precedence in Stash.pm hash ops guard#342Koan-Bot wants to merge 1 commit intoabw:masterfrom
Koan-Bot wants to merge 1 commit intoabw:masterfrom
Conversation
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>
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.
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 theelsifbranch could theoretically be entered for'import'even if the$HASH_OPSlookup 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
t/stash.t: 77/77 (2 new tests added)🤖 Generated with Claude Code