Commit fbf02ef3

fbf02ef3725cMerged

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

Description

codegen,analyze: Range#begin/#end, PolyArray#include?, String#delete_(pre|suf)fix!

Three small adjacent dispatch gaps:

  • Range#begin / Range#end (and Range#min / Range#max for the inclusive numeric form) alias to first / last in the range-method emitter, plus analyzer return-type entries.

  • Array#include? on poly_array now routes through sp_PolyArray_include with the arg boxed via box_expr_to_poly, matching the heterogeneous-array semantics.

  • String#delete_prefix! / String#delete_suffix! on mutable_str follow the existing chomp!/strip!/... pattern (sp_String_replace with the non-bang helper's output) and return the receiver.

Fixes #932 Fixes #942 Fixes #929

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

Details

Commit
fbf02ef3725c
Parent
24ec1cf637a4

spinel_analyze.rbmodifiedView file

@@ -4246,6 +4246,18 @@
42464246 if mname == "delete_prefix" || mname == "delete_suffix"
42474247 return "string"
42484248 end
4249+ if mname == "delete_prefix!" || mname == "delete_suffix!"
4250+ # Bang variants mutate self in place. When recv is mutable_str
4251+ # the call returns the same mutable_str; on a frozen literal
4252+ # the codegen path would already FrozenError before this fires.
4253+ if recv >= 0
4254+ rt_dpb = infer_type(recv)
4255+ if rt_dpb == "mutable_str"
4256+ return "mutable_str"
4257+ end
4258+ end
4259+ return "string"
4260+ end
42494261 if mname == "eql?"
42504262 return "bool"
42514263 end
@@ -5100,7 +5112,7 @@
51005112 end
51015113 return "int_array"
51025114 end
5103- if mname == "first" || mname == "last"
5115+ if mname == "first" || mname == "last" || mname == "begin" || mname == "end"
51045116 if recv >= 0
51055117 rt = infer_type(recv)
51065118 # Literal `[nil, ...].first` / `.last`: every element is nil so