Repository navigation
Proc/Method: advance MRI 4.0.6 conformance (bind, respond_to_missing, to_s encoding, post-splat blocks) - #557
Merged
Merged
Conversation
MRI only enforces the kind_of? bind-compatibility rule for methods owned by a Class; a method whose owner is a Module may be bound to any object. Fixes core/unboundmethod/bind and bind_call examples for module-owned UnboundMethods (Mod.instance_method(:foo).bind(anything)). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Object#method now returns a callable Method for a name answered only via
respond_to_missing?; its body forwards to method_missing (resolved at call
time) and it reports the receiver's class as #owner, the name as #name and
the receiver as #receiver. Two such Methods on the same receiver with the
same name compare == and hash equal (keyed on the name, since each is a
distinct record). Proc#to_s / #inspect are tagged ASCII-8BIT (BINARY) to
match MRI.
Fixes core/method/{call,name,owner,receiver,equal_value} and 5
core/proc/to_s binary-encoding examples.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
A non-lambda proc with post-splat required parameters (|*a, b|, |a, *b, c|) must not raise on too few arguments: MRI fills the post parameters with nil and leaves the splat empty. bindBlockPositionals now pads up to the leading required count plus the post-splat count, so exec's splat binding shapes the result instead of raising ArgumentError. Fixes two language/proc_spec 'assigns [] when passed no values' examples. 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 MRI-Ruby-4.0.6 conformance for the Proc / Method / UnboundMethod cluster. Four independent, tested fixes:
UnboundMethod#bind / #bind_call — module-owned methods bind to any receiver. MRI only enforces the
kind_of?bind-compatibility rule for methods owned by a Class; a method whose owner is a Module (e.g.Mod.instance_method(:foo), or a Kernel method likeObject.instance_method(:instance_of?)) may bind to any object.checkBindablenow short-circuits when the owner is a module.Object#method for names answered only via
respond_to_missing?. Returns a callable Method whose body forwards tomethod_missing(name, *args, &blk), resolved dynamically at call time; it reports the receiver's class as#owner, the name as#name, and the receiver as#receiver. Two such Methods on the same receiver with the same name compare==and#hashequal (keyed on the name, since each is a distinct record).Proc#to_s / #inspect are tagged ASCII-8BIT (BINARY), matching MRI's reported encoding.
Proc block binding — lenient post-splat required params. A non-lambda proc with post-splat required parameters (
|*a, b|,|a, *b, c|) no longer raises on too few arguments: the post parameters fill withniland the splat stays empty, as MRI does.Spec deltas (rubyspec, MRI 4.0.6)
core/unboundmethod/bind6→7,bind_call4→5 passcore/method/call1→5,name2→3,owner3→4,receiver2→3,equal_value11→13 passcore/proc/to_s1→6 passlanguage/proc_spec33→35 pass (two post-splat errors cleared)Verification
go test ./internal/vm/andgo test ./...greenGOOS=js GOARCH=wasmbuild OKgofmt -l internal/vm/emptyOut of scope (reported, not attempted)
Proc/Methodsource_location file:line and the spec's own__LINE__need per-node compiler line tracking.klassfield and ivar storage on theProcstruct.Method#super_methodafter aliasing an inherited method needs body-owner tracking through aliases.|(a, b)|block destructuring via#to_aryneeds a to_ary-based destructure opcode distinct from splat's#to_a(compiler/bytecode).12.method(:+)) are not resolvable as Method records.🤖 Generated with Claude Code