Commit e987ab57
e987ab57f8e8Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 4 files · +2 added · ~2 modified
Description
analyze,codegen: Numeric#coerce returns a typed-array pair
1.coerce(2.5) SEGV'd: the call dropped into the unresolved-call
int path (emitting 0), and the a, b = ... destructure then
dereferenced that int as a pointer.
CRuby's contract: recv.coerce(other) returns [other_cast, recv_cast] where both are widened to Float when either operand is
Float, else both stay Integer. Materialise that pair directly into
the matching typed array so the existing multi-write destructure
handles it without any new plumbing.
- analyze: infer_call_type returns float_array when either operand is float, int_array when both are int (recv is int/float).
- codegen: arm in compile_int_method_expr and compile_float_method_expr pushes the two coerced operands into a fresh FloatArray or IntArray.
Note: assigning the destructure to the same locals across calls with different operand types still widens those locals via spinel's body-usage type inference — that's the existing typed-var policy, not a coerce-specific bug.
Fixes #961
Co-Authored-By: Claude Opus 4.7 [email protected]
Details
- Commit
- e987ab57f8e8
- Parent
- d0938bda3d92
spinel_analyze.rbmodifiedView file
end # `(a..b).step(n)` (no block) -- returns an int_array of stepped # values. Issue #731. if mname == "coerce" if recv >= 0 rt_co = infer_type(recv) if rt_co == "int" || rt_co == "float" arg_t_co = "" args_id_co = @nd_arguments[nid] if args_id_co >= 0 aa_co = get_args(args_id_co) if aa_co.length > 0 arg_t_co = infer_type(aa_co[0]) end end if rt_co == "float" || arg_t_co == "float" return "float_array" end if arg_t_co == "int" return "int_array" end end end end if mname == "step" if recv >= 0 rt_step = infer_type(recv)spinel_codegen.rbmodifiedView file
Loading diff…
test/numeric_coerce.rbaddedView file
Loading diff…
test/numeric_coerce.rb.expectedaddedView file
Loading diff…