feat(vm): Module/Class residual surface — const_get/const_defined? paths, const_missing, included_modules, remove_class_variable - #341
Merged
Conversation
…g, included_modules, remove_class_variable Horodate: 2026-08-09 20:55 CEST Rework Module#const_get / #const_defined? to MRI 3.4/4.0 semantics and add the default Module#const_missing hook, Module#included_modules and Module#remove_class_variable, plus NameError#name. - const_get / const_defined?: accept a String, Symbol or #to_str object; resolve scoped "A::B" paths and a leading "::" toplevel qualifier; honour the inherit flag (default true, coerced to boolean); reject malformed names (NameError) and scoping into a non-module (TypeError). const_get routes an unresolved name through #const_missing; const_defined? reports a pending autoload without triggering the require. - const_missing: default hook raising NameError (no "Object::" prefix at the toplevel), carrying the name so NameError#name reports it. The `::` scope operator (scopedConst) now fires the hook, so user overrides apply. - included_modules: the modules (includes + prepends, transitively) in the ancestor chain, excluding the receiver. - remove_class_variable: removes a class variable defined directly on the receiver and returns its value; NameError on a malformed or absent name. Verified against ruby 4.0.5. ruby/spec core/module deltas: const_get 26->42, const_defined? 19->29, const_missing 1->5, included_modules 0->1, remove_class_variable 5->7. New table-driven tests in module_residuals_test.go. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Horodate: 2026-08-09 21:10 CEST The Module/Class residual work (const_get/const_defined? paths + inherit + #to_str + #const_missing, included_modules, remove_class_variable, NameError#name) lifts ruby/spec to 12284 passing. Lock in at N-30 (12254) per convention. 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.
Horodate: 2026-08-09 21:12 CEST
Completes the residual
Module/Classreflection surface toward MRI 3.4/4.0, verified againstruby 4.0.5.What's implemented
Module#const_get/#const_defined?— reworked to MRI semantics:String,Symbolor#to_str-coercible name;"A::B"paths and a leading"::"toplevel qualifier;inheritflag (defaulttrue, coerced to boolean) — inherit searches the ancestor chain and, for a first segment, falls back to the toplevel;inherit=falseconsults only the receiver's own table;NameError "wrong constant name", incl. empty/successive::segments) and scoping into a non-module (TypeError "… does not refer to class/module");const_getroutes an unresolved name through#const_missing;const_defined?reports a pending autoload as defined without triggering the require.Module#const_missing— default hook raisingNameError(omitting theObject::prefix at the toplevel, per MRI), carrying the name soNameError#namereports it. The::scope operator now fires the hook, so user overrides (including aprivate_class_method :const_missing) apply.Module#included_modules— the modules (includes + prepends, transitively) in the ancestor chain, excluding the receiver.Module#remove_class_variable— removes a class variable defined directly on the receiver and returns its value;NameErroron a malformed or absent name.Deferred (blocked by separate, pre-existing bugs — out of this scope)
const_source_location— needs per-constant source-location tracking threaded through constant assignment (invasive; no location is stored today).Objectat the toplevel, and const_defined? "special cases Object" — blocked by top-levelKernel#includenot including intoObject(Object.include?(M)isfalse;Mis absent from subclasses' ancestors).remove_class_variable"returns the value …" spec — blocked byModule#dupnot copying class variables.Verification
ruby/spec core/moduledeltas:const_get26→42,const_defined?19→29,const_missing1→5,included_modules0→1,remove_class_variable5→7.FLOORbumped to 12254 (N-30).GOWORK=off go test ./...— pass (exit 0), no regressions.-coverpkgallinternal/...): every added/touched function (incl. modifiedscopedConst,NameError#name) is 100%; the non-100% list is exactly the pre-existing tolerated partials.gofmtclean;go vet ./internal/vm/clean.New table-driven tests in
internal/vm/module_residuals_test.go.🤖 Generated with Claude Code