Repository navigation
vm: reset singleton-class body visibility to public on class << obj entry - #603
Merged
Merged
Conversation
… entry (core/kernel +3, language/def +1) OpOpenSingletonClass ran the `class << obj` body against the object's persistent singleton class (a class's cached metaclass, or an object's cached singleton) without resetting its defaultVis/funcMode. So a bare `private`/`protected` in one `class << self` block leaked into a later reopened block: a public singleton method defined after a `private` in a prior block wrongly became private. MRI resets scope visibility to public on every class/module/singleton frame push (vm_insnhelper.c), which defineClassIn/defineModuleIn already mirror. Do the same on the singleton-class-open path: `sc.defaultVis, sc.funcMode = visPublic, false` before running the body. The reset is body-entry only, so an in-block `private` still applies to defs that follow it in the same block. Verified byte-for-byte against MRI 4.0.5 (reopened `class << self` with private/protected/public, per-object singleton reopen, module receiver, private_class_method interplay, no-arg mode switch). ruby/spec language+core: 19992 -> 19996 (core/kernel methods_spec +1, public_methods_spec +2, language/def_spec +1), no regressions. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
tannevaled
added a commit
that referenced
this pull request
Sep 10, 2026
…606) First run past 20,000 passing ruby/spec examples. Wave-22 merged three bibliography-first conformance PRs: - #605 core/io: IO.pipe encodings, IO#write/write_nonblock transcoding, bom| handling, off_t RangeError, IO.foreach $./$_, IO#readpartial, IO.copy_stream with duck-typed sources and destinations — +77. - #604 core/kernel: Kernel#putc (new), #p/#print/#puts forwarding through $stdout so a mocked stream observes them, #p rendering per MRI rb_inspect — +15. - #603 VM: OpOpenSingletonClass now resets defaultVis, so a private in one 'class << self' body no longer leaks into a later reopened one — +4. Measured total on merged main: 20093 passing. Local measure at TIMEOUT=25; CI runs TIMEOUT=60 so its total is >= this floor. Co-authored-by: Claude Opus 5 (1M context) <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.
The bug
OpOpenSingletonClass(theclass << objopcode) ran the singleton bodyagainst the object's persistent singleton class — a class's cached
metaclass, or an object's cached singleton — without resetting its
defaultVis/funcMode. So a bareprivate/protectedin oneclass << selfblock leaked into a later reopened block: a publicsingleton method defined after a
privatein a prior block wrongly becameprivate (and vice-versa). Two prior conformance waves (19/20/21) flagged
this as blocking core/kernel and core/module
methods/public_methods.The fix
One line in the
OpOpenSingletonClasshandler, mirroring whatdefineClassIn/defineModuleInalready do for every ordinary class/module(re)open — MRI resets scope visibility to public on every
class/module/singleton frame push (
vm_insnhelper.c):The reset is body-entry only, so an in-block
privatestill applies todefs that follow it in the same block. The ordinary class/module path is
untouched.
Verification
Byte-for-byte against MRI Ruby 4.0.5 for every shape changed: reopened
class << selfwith private/protected/public,def self.xafter aclass << selfprivate, per-object singleton reopen, module receiver,private_class_methodinterplay, and no-arg mode switches. New whiteboxtest
internal/vm/singleton_vis_reset_test.go(added line covered,count=27).
ruby/spec language+core (frozen shim, pinned SHA): 19992 -> 19996
(+4). The only three files that moved, all improvements, all
visibility-related:
(
Module#methods/#public_methodsare exercised by the Kernel specs.)No regression across the whole corpus — identical file-load set, no other
file's pass count changed.
Gates:
go build ./...,GOWORK=off go test ./...(green), wasip1 build,gofmt -l internal/vm/empty.🤖 Generated with Claude Code