fix: reject attribute names that shadow lifecycle methods#37
Draft
Koan-Bot wants to merge 1 commit into
Draft
Conversation
Declaring an attribute named 'build', 'initialize', '_before_build', '_after_build', or '_strict_constructor' silently replaced the constructor lifecycle method with an accessor, causing the constructor to malfunction (e.g., falsy return from accessor aborts construction). Validate attribute names against a reserved list at import time, before any accessor installation, so the error is clean with no partial state. 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
Die at import time if an attribute name conflicts with a constructor lifecycle method.
Why
Declaring an attribute named
build,initialize,_before_build,_after_build,or
_strict_constructorsilently replaces the lifecycle method with an accessor.This causes the constructor to malfunction — e.g., a falsy
buildattribute valueaborts construction via the
return unless $self->$init(%opts)check.The bug is silent and hard to debug: no warning, no error, just broken
new().How
Added a
%_RESERVEDhash with the 7 lifecycle method names. Validation runs inimport()before_add_new/_add_accessors, so a rejected import leaves nopartial state (no accessors, no
new, nowithinstalled).Testing
12 new tests in
t/19-reserved-attr-names.t:building,initialized,before_build) work fine🤖 Generated with Claude Code
Quality Report
Changes: 2 files changed, 75 insertions(+)
Code scan: clean
Tests: passed (OK)
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline