Commit efd722c6

efd722c62538Merged

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

Description

codegen,analyze: Comparable#clamp on string via strcmp

"b".clamp("a", "c") fell through to the unresolved-call fallback. Add a String arm in compile_string_method_expr that single-evaluates the receiver and bounds into temps, then picks via strcmp.

Refs #899

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

Details

Commit
efd722c62538
Parent
b7602e5924b5

spinel_analyze.rbmodifiedView file

@@ -4296,6 +4296,13 @@
42964296 return "int"
42974297 end
42984298 if mname == "clamp"
4299+ # Issue #899: clamp on string receiver returns string.
4300+ if recv >= 0
4301+ rt_clamp = infer_type(recv)
4302+ if rt_clamp == "string" || rt_clamp == "mutable_str"
4303+ return "string"
4304+ end
4305+ end
42994306 return "int"
43004307 end
43014308 if mname == "itself" || mname == "tap"