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
end if @current_method_name != "" cls_idx = @current_method_name.index("_cls_") if cls_idx >= 0 # CRuby returns nil when not found; spinel runtime returns -1. if cls_idx != nil && cls_idx >= 0 return @current_method_name[0, cls_idx] end end mp = "" else idx = mp.rindex("_") if idx < 0 # CRuby returns nil when not found; spinel runtime returns -1. if idx == nil || idx < 0 mp = "" else mp = mp[0, idx]test/codegen_class_in_module_with_explicit_parent.rbaddedView file
Loading diff…
test/codegen_class_in_module_with_explicit_parent.rb.expectedaddedView file
Loading diff…
test/codegen_const_lookup_in_toplevel_method.rbaddedView file
Loading diff…
test/codegen_const_lookup_in_toplevel_method.rb.expectedaddedView file
Loading diff…