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

@@ -8419,6 +8419,10 @@
84198419 # Parent name might be a built-in (e.g., `class Foo < Numeric`)
84208420 ppidx = builtin_class_id_for_name(ppname)
84218421 end
8422+ else
8423+ # No explicit parent → Object. Without this default, `A.superclass`
8424+ # returned the -1 nil sentinel and printed empty instead of `Object`.
8425+ ppidx = builtin_class_id_for_name("Object")
84228426 end
84238427 parents_line = parents_line + ppidx.to_s + "LL"
84248428 pi_pl = pi_pl + 1