Skip to content

fix: wrap _assign() method calls in eval with hash fallback#415

Open
toddr-bot wants to merge 1 commit into
mainfrom
koan.toddr.bot/fix-assign-eval-wrapper
Open

fix: wrap _assign() method calls in eval with hash fallback#415
toddr-bot wants to merge 1 commit into
mainfrom
koan.toddr.bot/fix-assign-eval-wrapper

Conversation

@toddr-bot
Copy link
Copy Markdown
Contributor

What

Add eval wrapping and hash-access fallback to _assign() for blessed object method calls.

Why

The _assign() method called $root->$item(...) on blessed objects without an eval wrapper — a long-standing TODO noted in the commented-out code at lines 622-637. When the object is a blessed hashref and the method doesn't exist, the assignment silently failed instead of falling back to hash key access.

This is inconsistent with:

  • _dotop() (line 496) which wraps method calls in eval and falls back to hash/array ops
  • The XS stash assign() which checks method existence via gv_fetchmethod_autoload before calling

How

  • Wrap both the default-check and assignment method calls in eval { }
  • Propagate real errors (exception objects or methods that exist but throw)
  • Fall back to hash key assignment for hash-based objects when method is missing
  • Mirrors the same pattern used in _dotop() for consistency

Builds on PR #384 (the isa() fix for $atroot detection).

Testing

  • Added 3 tests with a PartialObject (blessed hashref with some methods): read method, read hash key, assign to hash key via fallback
  • Verified old code silently drops the assignment; new code correctly assigns via hash access
  • Full test suite passes (all 116 test files)

🤖 Generated with Claude Code


Quality Report

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

Code scan: clean

Tests: passed (OK)

Branch hygiene: clean

Generated by Kōan post-mission quality pipeline

_assign() called object methods without eval, unlike _dotop() and the
XS stash. When assigning to a property of a blessed hashref that lacks
the corresponding method, the assignment silently failed instead of
falling back to hash access.

Now mirrors _dotop() behaviour: try method call in eval, propagate real
errors, fall back to hash key assignment for hash-based objects.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@toddr-bot
Copy link
Copy Markdown
Contributor Author

Recreated from #385 (auto-closed when the toddr-bot fork was removed). Original branch is now hosted on this repo.

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