Skip to content

Proc/Method: advance MRI 4.0.6 conformance (bind, respond_to_missing, to_s encoding, post-splat blocks) - #557

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

tannevaled merged 3 commits into
mainfrom
feat/agent-proc2

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

Advances MRI-Ruby-4.0.6 conformance for the Proc / Method / UnboundMethod cluster. Four independent, tested fixes:

  1. 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 like Object.instance_method(:instance_of?)) may bind to any object. checkBindable now short-circuits when the owner is a module.

  2. Object#method for names answered only via respond_to_missing?. Returns a callable Method whose body forwards to method_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 #hash equal (keyed on the name, since each is a distinct record).

  3. Proc#to_s / #inspect are tagged ASCII-8BIT (BINARY), matching MRI's reported encoding.

  4. 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 with nil and the splat stays empty, as MRI does.

Spec deltas (rubyspec, MRI 4.0.6)

  • core/unboundmethod/bind 6→7, bind_call 4→5 pass
  • core/method/call 1→5, name 2→3, owner 3→4, receiver 2→3, equal_value 11→13 pass
  • core/proc/to_s 1→6 pass
  • language/proc_spec 33→35 pass (two post-splat errors cleared)

Verification

  • go test ./internal/vm/ and go test ./... green
  • GOOS=js GOARCH=wasm build OK
  • gofmt -l internal/vm/ empty
  • Every changed function at 100.0% coverage under the merged-coverage gate; no shadowed dead code.

Out of scope (reported, not attempted)

  • Proc/Method source_location file:line and the spec's own __LINE__ need per-node compiler line tracking.
  • Proc subclassing / clone / dup instance-variable + frozen copying needs a klass field and ivar storage on the Proc struct.
  • Method#super_method after aliasing an inherited method needs body-owner tracking through aliases.
  • |(a, b)| block destructuring via #to_ary needs a to_ary-based destructure opcode distinct from splat's #to_a (compiler/bytecode).
  • Operator methods on Integer (12.method(:+)) are not resolvable as Method records.

🤖 Generated with Claude Code

tannevaled and others added 3 commits September 4, 2026 12:09
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>
@tannevaled
tannevaled merged commit d5ba156 into main Sep 4, 2026
7 checks passed
@tannevaled
tannevaled deleted the feat/agent-proc2 branch September 4, 2026 11:32
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