Commit 46981e9c

46981e9ca3acMerged

Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 4 files · +2 added · ~2 modified

Description

codegen,analyze: Kernel#String() coercion routes through .to_s

String(42) / String(nil) / etc. fell through to the unresolved-call fallback. Add the Kernel arm that branches by argument type: int/float/bool/sym/bigint use the appropriate to_s helper; nil yields "" (per MRI); string passes through; poly dispatches through sp_poly_to_s.

Refs #879

Co-Authored-By: Claude Opus 4.7 [email protected]

Details

Commit
46981e9ca3ac
Parent
05b8746dad82

spinel_analyze.rbmodifiedView file

@@ -3762,7 +3762,7 @@
37623762 if is_primitive_shared_method(mname) == 1
37633763 return 1
37643764 end
3765- if mname == "Integer" || mname == "Float"
3765+ if mname == "Integer" || mname == "Float" || mname == "String"
37663766 return 1
37673767 end
37683768 if mname == "delete_prefix" || mname == "delete_suffix"
@@ -4130,6 +4130,10 @@
41304130 if recv < 0 && mname == "Float"
41314131 return "float"
41324132 end
4133+ # Kernel#String() returns string. Issue #879.
4134+ if recv < 0 && mname == "String"
4135+ return "string"
4136+ end
41334137 # Float#ceil(n)/floor(n)/round(n)/truncate(n) with n given return
41344138 # Float; zero-arg / Integer#ceil etc. return Integer. (truncate's arm
41354139 # used to live next to nan?/infinite? — folded in here for one place