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

@@ -3840,6 +3840,11 @@
38403840 return "bool"
38413841 end
38423842 end
3843+ # Numeric `<=>` is Integer (-1 / 0 / 1). int already resolves via
3844+ # its own arm; float was unresolved and fell back to emitting 0.
3845+ if lt == "float" && mname == "<=>"
3846+ return "int"
3847+ end
38433848 args_id = @nd_arguments[nid]
38443849 if args_id >= 0
38453850 aargs = parse_id_list(@nd_args[args_id])