Skip to content

fix: reject attribute names that shadow lifecycle methods#37

Draft
Koan-Bot wants to merge 1 commit into
masterfrom
koan.atoomic/fix-reserved-attr-names
Draft

fix: reject attribute names that shadow lifecycle methods#37
Koan-Bot wants to merge 1 commit into
masterfrom
koan.atoomic/fix-reserved-attr-names

Conversation

@Koan-Bot

@Koan-Bot Koan-Bot commented Apr 22, 2026

Copy link
Copy Markdown
Collaborator

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_constructor silently replaces the lifecycle method with an accessor.
This causes the constructor to malfunction — e.g., a falsy build attribute value
aborts 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 %_RESERVED hash with the 7 lifecycle method names. Validation runs in
import() before _add_new/_add_accessors, so a rejected import leaves no
partial state (no accessors, no new, no with installed).

Testing

12 new tests in t/19-reserved-attr-names.t:

  • All 7 reserved names are rejected with a clear error message
  • Near-miss names (building, initialized, before_build) work fine
  • Mixed list with a reserved name rejects the entire import (no partial install)
  • Full existing test suite passes

🤖 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

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>
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