Repository navigation
vm: language def/method/super/keyword-argument conformance (MRI 4.0.6) - #531
Merged
Merged
Conversation
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
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>
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 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
*splatpositional binding —def m(a,*b,c)never bound its post params (the splat consumed the tail,cstayed nil) and its arity minimum ignored them. Post params now bind from the tail and count toward the minimum arity.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). NewzsuperArgsreconstructs from the parameter locals.m(b: 1)ondef m(a:)→missing keyword: :a).initialize,initialize_copy,initialize_clone,initialize_dup,respond_to_missing?are defined private regardless of the surrounding default.defvisibility — adefexecuted inside a running method body is always public, not governed by the class's persisted default.#to_a→nil —*objwraps the object in a one-element array (a non-nil non-Array result stays a TypeError).superpast anundeftombstone — no longer invokes the nil body (crash); routes a failed super through a usermethod_missing, preserving the default "super: no superclass method" message.superfrom 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/)Verification
go test ./...green; wasm (GOOS=js GOARCH=wasm) build OK;gofmt -lclean on changed files.internal/vm/language_def_residuals_test.go.Out of scope (reported, not fixed)
Array#[]=does not auto-grow (a=[]; a[1]=14raises instead of[nil, 14]) — pre-existing array behaviour, exposed by the now-correct post-splat binding.definsideinstance_evalstill targets the receiver's class rather than its singleton (fix conflatesdef-target with constant-definition target — needs separating those in the frame model).block_spec.rb({after statement),lambda_spec.rb(->newline) fail to parse.SpecEvaluate/evaluateundefined) mask endless-method and kwarg-omitted-value examples.🤖 Generated with Claude Code