Skip to content

vm: language def/method/super/keyword-argument conformance (MRI 4.0.6) - #531

Merged
tannevaled merged 7 commits into
mainfrom
feat/agent-langdef
Aug 31, 2026
Merged

tannevaled merged 7 commits into
mainfrom
feat/agent-langdef

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

Advances rbgo conformance for the language def / method / super / keyword-argument cluster against MRI 4.0.6. All fixes are VM-side (single repo); no parser changes.

Fixes

  • Post-*splat positional binding — def m(a,*b,c) never bound its post params (the splat consumed the tail, c stayed nil) and its arity minimum ignored them. Post params now bind from the tail and count toward the minimum arity.
  • Implicit super (zsuper) — forwarded the original call arguments; MRI forwards the current values of the method's formal parameters (reassignments, filled-in optional/keyword defaults, splat/post rebinding). New zsuperArgs reconstructs from the parameter locals.
  • Keyword error order — a missing required keyword is now reported before an unknown one (m(b: 1) on def m(a:) → missing keyword: :a).
  • Auto-private hooks — initialize, initialize_copy, initialize_clone, initialize_dup, respond_to_missing? are defined private regardless of the surrounding default.
  • Nested def visibility — a def executed inside a running method body is always public, not governed by the class's persisted default.
  • Splat of #to_a→nil — *obj wraps the object in a one-element array (a non-nil non-Array result stays a TypeError).
  • super past an undef tombstone — no longer invokes the nil body (crash); routes a failed super through a user method_missing, preserving the default "super: no superclass method" message.
  • super from singleton methods and aliases — the ancestor walk starts at the object's singleton class, and the anchor uses the method's original name (so an aliased method's super resolves above the original owner).

Conformance deltas (rubyspec language/)

  • super_spec: 39 → 57 pass
  • method_spec: 26 → 36 pass
  • def_spec: 47 → 53 pass
  • keyword_arguments_spec: 9 → 10 pass

Verification

  • go test ./... green; wasm (GOOS=js GOARCH=wasm) build OK; gofmt -l clean on changed files.
  • Merged coverage 100.0%; every changed function at 100%.
  • Regression tests in internal/vm/language_def_residuals_test.go.

Out of scope (reported, not fixed)

  • Array#[]= does not auto-grow (a=[]; a[1]=14 raises instead of [nil, 14]) — pre-existing array behaviour, exposed by the now-correct post-splat binding.
  • def inside instance_eval still targets the receiver's class rather than its singleton (fix conflates def-target with constant-definition target — needs separating those in the frame model).
  • Parser gaps: block_spec.rb ({ after statement), lambda_spec.rb (-> newline) fail to parse.
  • Harness gaps (SpecEvaluate/evaluate undefined) mask endless-method and kwarg-omitted-value examples.

🤖 Generated with Claude Code

tannevaled and others added 7 commits August 31, 2026 15:36
Three MRI-conformance fixes in the argument-binding / super machinery:

- Post-*splat positional params (def m(a,*b,c)) were never bound: the
  splat greedily consumed the tail and post params stayed nil. Bind post
  params from the tail of the argument list and reserve them out of the
  splat, and enforce their required arity via iseqRequiredPositional so
  m(1) on def m(a,*b,c) raises "expected 2+".

- Implicit `super` (zsuper) forwarded the ORIGINAL call arguments. MRI
  forwards the CURRENT values of the method's formal parameters, so a
  reassigned local, a filled-in optional/keyword default, and splat/post
  rebinding are all reflected. Reconstruct the argument list from the
  parameter local slots (new zsuperArgs helper).

- A missing required keyword is now reported before an unknown one, as
  MRI does: m(b: 1) on def m(a:) raises "missing keyword: :a".

super_spec 39->52 pass (13->1 fail), method_spec 26->32, keyword_arguments
9->10. New regression tests in language_def_residuals_test.go.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
MRI always defines a small set of core hook methods with private
visibility, regardless of the current default: initialize,
initialize_copy, initialize_clone, initialize_dup, and
respond_to_missing?. Mark them private in OpDefineMethod.

language/def_spec 47->52 pass. Regression tests added.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The class default visibility (set by a bare `private`/`public` in the
class body) persists on the RClass and was wrongly applied to defs
executed later inside a method body. In MRI a `def` run inside a method
invocation is always public regardless of the class default; only defs
written directly in a class/module body (or a block at that level) follow
the default. Detect the method-body frame (selfBlock == nil, non-empty
methodName) and force public there.

Fixes the "resets visibility to public for nested definitions | in
Class.new" def_spec example. Regression tests added.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
`*obj` coercion (splatToArray) raised TypeError when obj#to_a returned
nil. MRI treats a nil result as "no array conversion" and wraps the
object in a one-element array, exactly as for an object without #to_a; a
non-nil non-Array result stays a TypeError. Fixes 8 language/method_spec
errors (splatted-object element/attribute assignment). Test added.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
invokeSuper invoked an `undef_method` tombstone (nil body) when a super
call's next definition was an undef blocker, crashing with a nil-pointer
deref. Treat an undefined tombstone as a non-callable blocker: stop the
ancestor search there, and — matching MRI — route a failed super through a
user-defined method_missing (the default one on BasicObject still yields
the "super: no superclass method" NoMethodError, preserving that message).

Fixes language/super_spec "calls method_missing when a superclass method
is not found" (was a process crash). Test added.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Two super-resolution fixes in invokeSuper / the frame's super anchor:

- A `super` from a per-object singleton method (def obj.foo, or a
  define_method on the singleton class) walked ancestors(classOf(self)),
  which omits the object's singleton class, so it never reached the
  class-level definition ("super: no superclass method"). Start the
  ancestor walk from the object's singleton class when it has one; its
  super is the object's class, so the class definition is found next.

- A `super` from an aliased method used the alias name (__callee__)
  rather than the method's original name (__method__), so it searched for
  the alias above the original owner and found nothing. Anchor super on
  fm.orig (the original name), matching MRI's "respects the original
  module a method is aliased from".

language/super_spec 53->57 pass. Regression tests added.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Coverage cleanup, no behaviour change on any tested path:
- The `if avail < 0` guard in post-splat binding is unreachable — the
  arity check (minReq includes the post params) guarantees
  len(args) >= npost — so it is removed.
- The bare-super block-frame branch no longer re-attaches env.kwargs: a
  block forwards the home method's captured args (as it always did before
  this cluster), while the method frame's keyword-aware reconstruction is
  the zsuperArgs path. This also restores the pre-change block behaviour.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@tannevaled
tannevaled merged commit 594c748 into main Aug 31, 2026
7 checks passed
@tannevaled
tannevaled deleted the feat/agent-langdef branch August 31, 2026 14:55
tannevaled added a commit that referenced this pull request Aug 31, 2026
Locks in the gains from #530 (Encoding compatibility: Converter.new,
concat negotiation, multibyte codepoints, ascii_only?), #531 (language
def/method/super/keyword-argument), #532 (Enumerable residuals) and #533
(Array/Hash value equality dispatching #==/#eql?/#hash). Measured 17654
passing on the pinned corpus, up from 17470.

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