Repository navigation
module: extend_object, const_source_location, const_added, cvar ancestry, Module.constants & definition hooks (core/module +19) - #595
Merged
Conversation
…arn, cvar ancestry, Module.constants, def hooks, .new block arg (core/module +19) Advance MRI-4.0.x conformance of Module/Class (core/module). Each change is byte-for-byte checked against local MRI 4.0.5 and cited to ruby/ruby v3_4_0. - Module#extend_object: the private primitive Object#extend dispatches to. Mixes self into the object's singleton class (methods + constants); TypeError when self is a Class (rb_include_module), FrozenError for a frozen object; undefined on Class. Ref object.c rb_mod_extend_object / rb_extend_object. - Module#const_source_location: rbgo tracks no per-constant source position, so it returns nil for a resolvable name (as MRI does for an absent one) while honouring the full NameError/TypeError name-validation contract. Ref variable.c rb_const_source_location. (+6, errors 35->1) - Module#const_set: fire const_added on every set (ref variable.c rb_const_set) and warn "already initialized constant" on redefining a real value, gated by $VERBOSE non-nil (rb_warn semantics; a pending autoload does not warn). - class_variable_get/_set/_defined? and #class_variables now search the whole ancestry (included modules), not only the superclass chain; _set writes through to the owning module. Ref variable.c rb_cvar_get / rb_cvar_set. - Module.constants (singleton): no-arg returns every top-level constant (equal to Object.constants); with an argument behaves like Module#constants. Ref variable.c rb_mod_s_constants. - Module#remove_const made private (rb_define_private_method). - remove_method / undef_method fire method_removed / method_undefined on an ordinary class (singleton classes keep routing to the singleton hooks). - Module.new / Class.new yield the new module/class to their block. Ref object.c rb_mod_initialize / rb_class_initialize -> rb_mod_module_exec(module,1,&module). Whitebox tests in module_wave20_test.go cover every new branch. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
tannevaled
added a commit
that referenced
this pull request
Sep 8, 2026
…598) Wave-20 merged three bibliography-first conformance PRs: - #596 core/io: File.open/new trailing-Hash options, IO#read/readchar/gets external->internal transcoding, IO#set_encoding_by_bom, BOM stripping — +62 (and core/file +8 incidental). - #597 core/enumerator: Enumerator::Product class, Chain/ArithmeticSequence constructors, Enumerator#take_while break-early (clearing the produce_spec hang) — +49. - #595 core/module: extend_object, const_source_location, const_set const_added + redefinition warning, class_variable ancestry search, Module.constants singleton, remove/undef_method hooks — +19. Measured total on merged main: 19915 passing (2172 files load, +1 that was a hang). Local measure at TIMEOUT=25; CI runs TIMEOUT=60 so its total is >= this floor. 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-4.0.x conformance of the
Module/Classsurface. Measured againstthe frozen ruby/spec corpus with a consistent harness, core/module goes
790 → 809 pass (+19), with errors dropping 102 → 66 (
const_source_locationalone converts 35 errors into resolved/nil results). Every behaviour was checked
byte-for-byte against local MRI 4.0.5 and cited to ruby/ruby
v3_4_0sources.Changes
Module#extend_object— the private primitiveObject#extenddispatches to.Mixes the module into the object's singleton class (methods and constants);
raises
TypeErrorwhen the receiver is a Class (rb_include_module), andFrozenErrorfor a frozen object; undefined onClass. Refobject.crb_mod_extend_object/rb_extend_object. (extend_object_spec +4)Module#const_source_location— rbgo records no per-constant sourceposition, so it returns
nilfor a resolvable name (the value MRI gives anabsent constant) while honouring MRI's full name-validation contract
(
NameErrorfor a malformed name or a Symbol carrying a scope path,TypeErrorfor a failed
#to_str). Refvariable.crb_const_source_location. (+6)Module#const_set— firesconst_addedon every set (refvariable.crb_const_set) and warnsalready initialized constanton redefining a realvalue, gated by
$VERBOSEnon-nil (rb_warn; a pending autoload does not warn).class_variable_get/_set/_defined?and#class_variablesnow searchthe whole ancestry (included modules), not only the superclass chain;
_setwrites through to the owning module. Ref
variable.crb_cvar_get/rb_cvar_set.Module.constants(singleton) — no argument returns every top-level constant(equal to
Object.constants); with an argument behaves likeModule#constants.Ref
variable.crb_mod_s_constants.Module#remove_constmade private (rb_define_private_method).remove_method/undef_methodfiremethod_removed/method_undefinedon an ordinary class; singleton classes keep routing to the singleton hooks.
Module.new/Class.newyield the new module/class to their block. Refobject.crb_mod_initialize/rb_class_initialize→rb_mod_module_exec(module, 1, &module).Testing
internal/vm/module_wave20_test.gocovers every new branch;go tool cover -funcshows 100% on all introduced code (the pre-existingbootstrap99.7% /cloneSingleton79.2% are untouched).go build ./..., fullGOWORK=off go test ./..., and thewasip1build all pass;gofmt -l internal/vm/is clean.core/struct, core/data unchanged.
🤖 Generated with Claude Code