Repository navigation
Module#define_method: MRI 4.0.6 arity, visibility, hooks, and bind checks - #525
Merged
Merged
Conversation
A method created by define_method (from a block or a non-lambda Proc) enforces method/lambda argument arity: it raises ArgumentError on a count mismatch and never auto-splats a lone Array argument, matching MRI 4.0.6. Mark the anchored body Proc as a lambda so bindBlockArgs routes through the strict path and exec's arity check fires. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Bring Module#define_method to MRI 4.0.6 for the remaining spec cluster:
- Visibility: a created method takes the receiver's current default
visibility (private/public/protected), is public when defined from
another module, and is always private for :initialize/:initialize_copy.
- Name coercion: a non-Symbol/String name is converted through #to_str;
a #to_str returning a non-String raises TypeError with MRI's message.
- The method_added hook fires once after the method is installed.
- A non-Proc/Method/UnboundMethod body raises the MRI TypeError naming
Proc/Method/UnboundMethod; a Proc/Method arg takes precedence over a
block; a frozen receiver raises FrozenError.
- A transplanted Method/UnboundMethod owned by a Class (or singleton
class) may only be re-homed onto that class or a subclass, else
TypeError ("bind argument must be a subclass of ..." / "can't bind
singleton method to a different class"); Module-owned and the Object/
BasicObject universal roots stay permissive.
Adds define_method_conformance_test.go and corrects a tier0 reflection
case that asserted the old, non-MRI lenient cross-class transplant.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
TestMethodOriginalName and the tier0 reflection case transplanted a Method/UnboundMethod onto an unrelated class, which MRI rejects. Make the target a subclass of the source so the tests still exercise original_name preservation and Method transplant under the MRI-correct bind-compatibility rule now enforced by define_method. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Add Go tests exercising the permissive module- and Object-owner branches of the transplant bind check, the singleton-owner rejection, and the always-private :initialize_copy case, bringing the changed functions to 100% MERGED coverage. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
tannevaled
added a commit
that referenced
this pull request
Aug 31, 2026
* Raise ruby/spec floor to 17470 after wave-3 conformance work Locks in the gains from #521 (regexp \xHH), #523 (String#encode fallback/xml/IBM437/default_internal), #524 (Marshal Data + Regexp encoding), #525 (Module#define_method arity/visibility/hooks) and #522 (sprintf %c/named-default/hex-float). Measured 17470 passing on the pinned corpus, up from 17310. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * ci: re-trigger after transient GOPROXY stream errors Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> --------- 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.
Module#define_method conformance (MRI 4.0.6)
Advances
core/module/define_method_spec.rbfrom 45 → 85 passing (of 88), with no regressions in the wider suite.Changes
callProcMethod): a define_method body — from a block or a non-lambda Proc — now binds arguments with method/lambda arity: ArgumentError on a count mismatch, and no auto-splat of a lone Array. (+22 examples):initialize/:initialize_copy.#to_str; a#to_strreturning a non-String raises the MRITypeError.TypeErrornamingProc/Method/UnboundMethod; a frozen receiver raisesFrozenError.TypeError("bind argument must be a subclass of …" / "can't bind singleton method to a different class"); Module-owned and the Object/BasicObject universal roots stay permissive.Files
internal/vm/object_model.go—callProcMethodlambda binding.internal/vm/builtins.go—define_methodnative rewrite.internal/vm/modulefunc.go—defineMethodName,defineMethodVis,checkTransplantBindable,fireMethodAddedhelpers.internal/vm/define_method_conformance_test.go— new coverage.Remaining 3 (out of scope for the define_method path)
#to_strnon-String message: rbgo emits MRI 4.0.6's exact "can't convert Object to String (…)"; the corpus regex expects the older "…into String".{ |a,| }two-arg arity andredo: parser/compiler representation, outsidemodulefunc.go/object_model.go.Verification
go test ./internal/vm/andgo test ./...green;GOOS=js GOARCH=wasmbuild OK;gofmt -lclean; MERGED coverage of all changed functions and the overall profile 100.0%.🤖 Generated with Claude Code