Skip to content

fix: correct DEFAULT assignment for array elements in Context stash - #460

Draft
toddr-bot wants to merge 1 commit into
mainfrom
koan.toddr.bot/fix-context-stash-default-array
Draft

fix: correct DEFAULT assignment for array elements in Context stash#460
toddr-bot wants to merge 1 commit into
mainfrom
koan.toddr.bot/fix-context-stash-default-array

Conversation

@toddr-bot

@toddr-bot toddr-bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

What

Fix a bug in Template::Stash::Context::_assign() where DEFAULT
assignment on array elements always overwrote existing values.

Why

The $default guard on line 625 used hash access ($root->{$item})
on an array ref instead of array access ($root->[$item]). Hash access
on an array ref always returns undef, so the guard never triggered —
DEFAULT list.0 = 'x' would silently overwrite an existing value at
index 0.

The parent class Template::Stash has the correct $root->[$item]
on the equivalent line 620.

How

One-character fix: {[ and }]. Also fixed a "Experimetal"
typo in the POD heading.

Testing

  • Added unit tests for DEFAULT assignment on array elements via
    _assign() API (verify existing values preserved, undefined slots
    filled)
  • Added template-level tests for DEFAULT mylist.0 = 'x' via
    test_expect with the Context stash
  • Full test suite passes

Quality Report

Changes: 2 files changed, 35 insertions(+), 2 deletions(-)

Code scan: clean

Tests: passed (OK)

Branch hygiene: clean

Generated by Kōan

…tash

In _assign(), the default-value guard for array elements used hash
access ($root->{$item}) instead of array access ($root->[$item]).
This caused DEFAULT assignments to always overwrite existing array
values because hash access on an array ref returns undef.

Also fix 'Experimetal' typo in POD heading.
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