Skip to content

vm: name anonymous classes in inspect and FrozenError; Set subclass inspect - #993

Merged
tannevaled merged 2 commits into
mainfrom
set-inspect
Nov 29, 2026
Merged

tannevaled merged 2 commits into
mainfrom
set-inspect

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

What

Anonymous classes. rb_obj_inspect, rb_any_to_s and the FrozenError message name the class through rb_class_name, which renders an anonymous class as its #<Class:0x…> identity. rbgo read the empty name field instead:

rbgo before MRI 4.0.10 / after
Class.new.new.inspect #<:0x…> #<#<Class:0x…>:0x…>
Class.new.new.to_s #<:0x…> #<#<Class:0x…>:0x…>
frozen instance, instance_variable_set can't modify frozen : #<:0x…> can't modify frozen #<Class:0x…>: #<#<Class:0x…>:0x…>

A new vm.classPath does what rb_class_name does, and those three paths use it.

Set subclasses. set_i_inspect (set.c, v4.0.10) prints the Set[…] literal form for Set itself only. A subclass keeps the older shape, #<Foo: {1, 2}>, with #<Foo: {...}> as its recursion marker; rbgo printed Set[…] for both. Set's repr now takes the VM, which lets it:

  • name an anonymous subclass;
  • inspect each member through Ruby.

Kernel#p and inspectStr now dispatch a Set's #inspect. As a result, p Set[obj] shows obj's own #inspect, and a subclass's #inspect override is honoured, as rb_inspect does.

Evidence

rubydiff against MRI 4.0.10 (ruby 4.0.10 (2026-11-19 revision a704b7cd95) +PRISM [arm64-darwin27]) on a 29-line probe: AGREE. The probe covers named and anonymous subclasses, nesting in Set, Array and Hash, recursion, a namespaced Outer::Set, member #inspect, a subclass #inspect override, and plain Set unchanged.

Tests

  • TestAnonymousClassInspect and TestSetSubclassInspect take MRI's output as their expectations.
  • A wider regression set (Inspect|Set|Frozen|Freeze|Anonymous|ToS|Kernel|Struct|Data|Exception|Error): 838 tests ran, none failed.
  • mutsweep (-sites all) on the four new branches: all caught.

Once #992 (Set freeze) is in, a frozen subclass's error also reads can't modify frozen Foo: #<Foo: {1}>, which the probe measured as matching MRI. It is not asserted here, because this branch has no Set freeze.

Refs #992

🤖 Generated with Claude Code

tannevaled and others added 2 commits November 29, 2026 18:31
…nspect

rb_obj_inspect, rb_any_to_s and the FrozenError message name the class
through rb_class_name, which renders an anonymous class as its
"#<Class:0x…>" identity. rbgo read the empty name and printed "#<:0x…>"
and "can't modify frozen : …". A new vm.classPath does what rb_class_name
does and the three paths use it.

set_i_inspect (set.c, v4.0.10) prints the "Set[…]" literal form for Set
itself only; a subclass keeps "#<Foo: {1, 2}>", with "#<Foo: {...}>" as
its recursion marker. rbgo printed "Set[…]" for both. Set's repr now takes
the VM to name an anonymous subclass and to inspect each member through
Ruby, and Kernel#p / inspectStr dispatch a Set's #inspect, so a member's
own #inspect and a subclass override are honoured, as rb_inspect does.

Measured against MRI 4.0.10 with rubydiff on 29 lines: AGREE.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The ubuntu coverage ratchet put Set#Inspect and repr at 0% and reprWith
at 94.7%: once Ruby's Set#inspect went through reprWith(vm), nothing in
the suite read the VM-less path a host program or a Go-side message
uses. TestSetGoInspect drives it for Set itself, a subclass and a Set
that contains itself, in set_i_inspect's MRI 4.0.10 shapes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tannevaled
tannevaled merged commit daa6505 into main Nov 29, 2026
26 checks passed
@tannevaled
tannevaled deleted the set-inspect branch November 29, 2026 20:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant