Commit 4dfadf3d
4dfadf3d5f26Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 2 files · ~2 modified
Description
fix(analyze,codegen): bigint#to_s inference doesn't yield to user-class to_s
infer_call_type's to_s arm returned "" (defer to user method
dispatch) whenever any user class defined a to_s imeth AND the
recv could be an obj. For a bigint receiver this defer was wrong:
sp_bigint_to_s is a fixed runtime dispatch that does not consult
user classes. The "" return left the cache empty, fell back to
"int" at codegen-side infer_type, and the outer string-concat path
wrapped the already-string sp_bigint_to_s emit with another
sp_int_to_s.
Add an early arm: if the recv's static type is bigint, return
"string" directly. Symptomatic in attr.rb where Point defines a
to_s method and an inner @x.to_s (bigint recv) needs the
runtime helper, not the user method.
Also add a bigint -> string arm to compile_expr_for_expected_type so a bigint value reaching an expected-string slot routes through sp_bigint_to_s. (Defensive fallback; not the primary fix here.)
Promote-mode test count: 514 pass / 47 fail / 57 error -> 516 pass / 48 fail / 54 error. Default raise mode unchanged at 618 / 0 / 0.
Co-Authored-By: Claude Opus 4.7 [email protected]
Details
- Commit
- 4dfadf3d5f26
- Parent
- bd0798ccbcbb
spinel_analyze.rbmodifiedView file
return "int" end if mname == "to_s" # `to_s` on a bigint recv always dispatches to sp_bigint_to_s # (defined in lib/sp_runtime.h), regardless of whether any user # class also defines a `to_s` method. The user-method dispatch # only matters when the recv could actually be a user obj. if recv >= 0 && infer_type(recv) == "bigint" return "string" end if recv_could_be_obj(recv) == 1 && any_user_class_defines_imeth(mname) == 1 return "" endspinel_codegen.rbmodifiedView file
Loading diff…