Repository navigation
BasicObject: advance MRI 4.0.6 conformance (core/basicobject residuals) - #559
Merged
Merged
Conversation
… 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>
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.
Advances
core/basicobject/*_spec.rbconformance toward MRI 4.0.6. The clustergoes 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 threesingleton_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-objectsingleton class records its attached object; a class metaclass uses its
metaOfback-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 ahook 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_added1→11,_removed0→2,
_undefined0→2)instance_eval / instance_exec (block form) — now run with the receiver's
singleton class as the method-def target, so a
defin the block becomes asingleton method of the receiver instead of leaking onto the block's home
namespace, and
instance_evalyields the receiver to the block. The redirect isthreaded separately (only
def/alias/undefretarget) so constants, classvariables and
class/modulereopenings in the block still resolve lexically —matching MRI and the conformance harness's own
instance_eval-run examplebodies. (
instance_eval21→24,instance_exec14→15)method_missing — an explicit-receiver private/protected call now reaches the
receiver's
#method_missingwhen defined, else raises a NoMethodError stampedwith
@receiver/@name/@args; an undefined call on a class/module receiverresolves
#method_missingthrough the receiver's singleton (class) methods first(so
def self.method_missinghandles unknown class methods). (method_missing21→30)
initialize — the default
BasicObject#initializenow takes no arguments, sonewwith arguments (or a subclass forwarding viasuper) raises ArgumentError.(
initialize1→2)Verification
internal/vmsuite green;go test ./...green; wasm build OK;gofmtclean.
internal/vm/basicobject_residuals_test.go); no shadowed dead code.core/*tree pluslanguageshow zero regressions.
Remaining
core/basicobjectfailures are deliberately deferred as out-of-scopeor 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