Commit 1b98c468
1b98c4681c89Merged
Ryan Seys <[email protected]> · 6 months ago · 4 files · +2 added · ~2 modified
Description
codegen: Class#superclass returns Object for parentless classes
class A; end; puts A.superclass printed empty: the
sp_class_parents[] table entry stored -1 (no explicit
parent) and sp_class_to_s(-1) returns the empty string for
the nil-sentinel cls_id. CRuby's A.superclass returns
Object — every class implicitly inherits from Object.
When emitting the per-user-class entry of sp_class_parents[]
(at the point where ppname == "" means no < Parent clause),
default the parent index to the builtin Object cls_id instead
of -1. Modules keep their existing -1 (no superclass concept).
Classes that DO declare a parent (class B < A) still resolve
to that parent — only the no-parent case changes.
Existing tests already exercise the explicit-parent path; the new test adds the no-parent case.
Co-Authored-By: Claude Opus 4.7 [email protected]
Details
- Commit
- 1b98c4681c89
- Parent
- e4d2ffaa5870
spinel_codegen.rbmodifiedView file
# Parent name might be a built-in (e.g., `class Foo < Numeric`) ppidx = builtin_class_id_for_name(ppname) end else # No explicit parent → Object. Without this default, `A.superclass` # returned the -1 nil sentinel and printed empty instead of `Object`. ppidx = builtin_class_id_for_name("Object") end parents_line = parents_line + ppidx.to_s + "LL" pi_pl = pi_pl + 1test/class_hierarchy.rbmodifiedView file
Loading diff…
test/class_superclass.rbaddedView file
Loading diff…
test/class_superclass.rb.expectedaddedView file
Loading diff…