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) == 137633763
return 137643764
end3765-
if mname == "Integer" || mname == "Float"3765+
if mname == "Integer" || mname == "Float" || mname == "String"37663766
return 137673767
end37683768
if mname == "delete_prefix" || mname == "delete_suffix"@@ -4130,6 +4130,10 @@
41304130
if recv < 0 && mname == "Float"41314131
return "float"41324132
end4133+
# Kernel#String() returns string. Issue #879.4134+
if recv < 0 && mname == "String"4135+
return "string"4136+
end41334137
# Float#ceil(n)/floor(n)/round(n)/truncate(n) with n given return41344138
# Float; zero-arg / Integer#ceil etc. return Integer. (truncate's arm41354139
# used to live next to nan?/infinite? — folded in here for one placespinel_codegen.rbmodifiedView file
Loading diff…
test/kernel_string_coercion.rbaddedView file
Loading diff…
test/kernel_string_coercion.rb.expectedaddedView file
Loading diff…