Skip to content

BasicObject: advance MRI 4.0.6 conformance (core/basicobject residuals) - #559

Merged
tannevaled merged 4 commits into
mainfrom
feat/agent-basicobj
Sep 4, 2026
Merged

tannevaled merged 4 commits into
mainfrom
feat/agent-basicobj

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

Advances core/basicobject/*_spec.rb conformance toward MRI 4.0.6. The cluster
goes from 117 → 145 passing examples (fail 48→24, error 22→2), with these
specs now fully green: __id__, __send__, equal_value, initialize,
method_missing, not_equal, not, and all three singleton_method_* hooks.

What changed

singleton_method_added / _removed / _undefined hooks — defined as private
no-op instance methods on BasicObject and fired, as MRI, on the object that owns
a singleton method whenever one is added, removed, or undefined (via def obj.x
/ def self.x, class << self, define_method, define_singleton_method,
alias/alias_method, remove_method, undef/undef_method). A per-object
singleton class records its attached object; a class metaclass uses its metaOf
back-pointer. Firing skips the default no-op so ordinary defs stay cheap, and an
undef'd hook routes to method_missing (NoMethodError by default). Undef of a
hook whose default lives on BasicObject but is reachable only through the
attached object (a metaclass's super chain doesn't bridge to BasicObject's
instance methods) is now permitted. (singleton_method_added 1→11, _removed
0→2, _undefined 0→2)

instance_eval / instance_exec (block form) — now run with the receiver's
singleton class as the method-def target, so a def in the block becomes a
singleton method of the receiver instead of leaking onto the block's home
namespace, and instance_eval yields the receiver to the block. The redirect is
threaded separately (only def/alias/undef retarget) so constants, class
variables and class/module reopenings in the block still resolve lexically —
matching MRI and the conformance harness's own instance_eval-run example
bodies. (instance_eval 21→24, instance_exec 14→15)

method_missing — an explicit-receiver private/protected call now reaches the
receiver's #method_missing when defined, else raises a NoMethodError stamped
with @receiver/@name/@args; an undefined call on a class/module receiver
resolves #method_missing through the receiver's singleton (class) methods first
(so def self.method_missing handles unknown class methods). (method_missing
21→30)

initialize — the default BasicObject#initialize now takes no arguments, so
new with arguments (or a subclass forwarding via super) raises ArgumentError.
(initialize 1→2)

Verification

  • Full internal/vm suite green; go test ./... green; wasm build OK; gofmt
    clean.
  • Every function changed is 100% covered (new tests in
    internal/vm/basicobject_residuals_test.go); no shadowed dead code.
  • Base-vs-new conformance sweeps over the full core/* tree plus language
    show zero regressions.

Remaining core/basicobject failures are deliberately deferred as out-of-scope
or high-risk: BasicObject constant-boundary resolution and Kernel-method
modeling (basicobject_spec), equal?-is-an-alias-of-== (entangled with ==
value-equality semantics), instance_eval String-form caller-scope constant/local
lookup and file/lineno backtrace threading, and def-on-immediate TypeError.

🤖 Generated with Claude Code

tannevaled and others added 4 commits September 4, 2026 12:21
… 4.0.6)

Define the three singleton-method definition hooks as private no-op instance
methods on BasicObject and fire them, matching MRI, on the object that owns a
singleton method whenever one is added, removed, or undefined — via def obj.x /
def self.x, class << self, define_method, define_singleton_method, alias /
alias_method, remove_method, and undef / undef_method. A per-object singleton
class now records its attached object so the hook has a receiver; a class
metaclass uses its metaOf back-pointer.

Firing routes through a resolver that skips the BasicObject default no-op (so
ordinary defs stay cheap) and, when the hook has been undef'd, dispatches to the
object's method_missing (NoMethodError by default) exactly as MRI does. undef of
a hook whose default lives on BasicObject but is reachable only through the
attached object (a metaclass's super chain does not bridge to BasicObject's
instance methods) is now permitted.

core/basicobject singleton_method_{added,removed,undefined} specs go from
1/0/0 passing to 11/2/2 (all green). Updates the stale core-methods test to
MRI's private_instance_methods set.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…receiver

The block form of instance_eval/instance_exec now runs with the receiver's
singleton class as the method-definition target (a class/module's metaclass, else
a per-object singleton class), so a `def` inside the block becomes a singleton
method of the receiver instead of leaking onto the block's home namespace — and
instance_eval yields the receiver to the block. A def inside the block fires
singleton_method_added on the receiver, as MRI.

The method-def redirect is threaded separately (pendingEvalMethodDefinee →
methodDefinee) so it applies ONLY to def/alias/undef; the frame's definee stays
the block's lexical scope, keeping constant lookup, `class`/`module` reopenings,
and class-variable resolution lexical — matching MRI and, critically, the way the
conformance harness itself runs example bodies via instance_eval.

core/basicobject instance_eval 21→24, instance_exec 14→15. No regressions across
core/{basicobject,kernel,proc,method,class,module} and language (base-vs-new
sweep clean); full internal/vm suite green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…ach class hook

An explicit-receiver send to a private (or out-of-scope protected) method now
reaches the receiver's #method_missing when it defines one, instead of raising
outright — and when it does raise, the NoMethodError carries @receiver/@name/@Args
so NoMethodError#receiver reports the failed call (MRI). The visibility gate on
the plain OpSend paths is replaced by enforceSendVisRoute/explicitBlockedRoute,
which resolve the block kind without raising and either invoke a user
#method_missing (with the name, args and block) or raise the stamped error; the
splat/block-argument OpSend forms keep the raise-only gate (now also stamped).

An undefined call on a class/module receiver now resolves #method_missing through
the receiver's singleton (class) methods first, so `def self.method_missing`
handles an unknown class method before the generic Class/BasicObject default.

core/basicobject method_missing 21→30 (all green). No regressions across
core/{kernel,basicobject,module,method,object,class,comparable,struct} or
language (base-vs-new sweep clean); full internal/vm suite green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The default BasicObject#initialize takes no arguments, so BasicObject.new /
Object.new with arguments — or a subclass that forwards them here via `super` —
now raises ArgumentError, matching MRI. A zero-argument new is unaffected.

core/basicobject initialize 1→2 (all green). No regressions across the full
core/* conformance sweep; internal/vm suite green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@tannevaled
tannevaled merged commit c4fb968 into main Sep 4, 2026
12 of 13 checks passed
@tannevaled
tannevaled deleted the feat/agent-basicobj branch September 4, 2026 13:03
tannevaled added a commit that referenced this pull request Sep 4, 2026
Locks in #557 (Proc/Method/UnboundMethod), #558 (Array) and #559
(BasicObject). Measured 18582 passing on the pinned corpus, up from 18354.

Co-authored-by: Claude Opus 4.8 <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