Commit 09f5d8cd
09f5d8cd2fdcMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 3 files · +1 added · ~2 modified
Description
Implement Float#<=> 3-way compare
3.0 <=> 5.0 raised "undefined method '<=>' for float": the analyzer
left a float-recv <=> unresolved (only int and Time had arms) and
codegen had no float <=> branch, so it emitted 0 and the C call
failed. This also blocked float comparator blocks — floats.sort { |a,b| a <=> b }, min/max/minmax with a block.
Add the float arm in both passes: infer_operator_type returns int for
float <=> _, and compile_float_method_expr emits the
a < b ? -1 : (a > b ? 1 : 0) form for an int/float argument (mirroring
the int-recv arm). A non-numeric argument still falls through.
Co-Authored-By: Claude Opus 4.8 [email protected]
Details
- Commit
- 09f5d8cd2fdc
- Parent
- 3847676723d4
spinel_analyze.rbmodifiedView file
return "bool" end end # Numeric `<=>` is Integer (-1 / 0 / 1). int already resolves via # its own arm; float was unresolved and fell back to emitting 0. if lt == "float" && mname == "<=>" return "int" end args_id = @nd_arguments[nid] if args_id >= 0 aargs = parse_id_list(@nd_args[args_id])spinel_codegen.rbmodifiedView file
Loading diff…
test/float_spaceship.rbaddedView file
Loading diff…