Commit 6b9e6f19

6b9e6f1988baMerged

Yusuke Endoh <[email protected]> · 6 months ago · 5 files · +4 added · ~1 modified

Description

fix(codegen): CRuby-compat for two String#index / #rindex sites

spinel_codegen.rb is dual-targeted: spinel itself compiles it (via the bootstrap), and CRuby runs it directly when the compiled binary is unavailable (./spinel falls back to ruby spinel_codegen.rb). The two runtimes differ on String#index / #rindex when the substring isn't found:

  • CRuby returns nil
  • Spinel's runtime returns -1

Most existing call sites already guard with idx == nil || idx < 0 (see e.g. trim_const_scope_once). Two sites missed the guard and crashed under CRuby with NoMethodError: undefined method '<' for nil:

  • current_lexical_scope_name: cls_idx = @current_method_name.index("_cls_")
  • collect_class_with_prefix: idx = mp.rindex("_")

Add the same guard. Unblocks fast-iteration testing where running the codegen pass through CRuby (skipping the ~30s bootstrap) cuts the per-edit cycle time.

Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]

Details

Commit
6b9e6f1988ba
Parent
9153a62f417c

spinel_codegen.rbmodifiedView file

@@ -1230,7 +1230,8 @@
12301230 end
12311231 if @current_method_name != ""
12321232 cls_idx = @current_method_name.index("_cls_")
1233- if cls_idx >= 0
1233+ # CRuby returns nil when not found; spinel runtime returns -1.
1234+ if cls_idx != nil && cls_idx >= 0
12341235 return @current_method_name[0, cls_idx]
12351236 end
12361237 end
@@ -7102,7 +7103,8 @@
71027103 mp = ""
71037104 else
71047105 idx = mp.rindex("_")
7105- if idx < 0
7106+ # CRuby returns nil when not found; spinel runtime returns -1.
7107+ if idx == nil || idx < 0
71067108 mp = ""
71077109 else
71087110 mp = mp[0, idx]