Commit cf92cced
cf92cced4f1eMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 1 file · ~1 modified
Description
fix(codegen): Comparable < / > / <= / >= unbox <=> bigint result
A user class that defines def <=> and include Comparable lowers
relational operators to (_cmp_call < 0) etc. Under promote mode
the body's @grams - other.grams returns sp_Bigint *, so the
comparison degenerates to a NULL-check on the pointer rather than
on the int value.
Detect via cls_method_return and unbox the call result with sp_bigint_to_int before the relational compare.
Picks up lrama_features under promote.
Co-Authored-By: Claude Opus 4.7 [email protected]
Details
- Commit
- cf92cced4f1e
- Parent
- 312589b2180b
spinel_codegen.rbmodifiedView file
@@ -15535,6 +15535,14 @@
1553515535
ca = compile_typed_call_args_by_name(nid, cmp_owner, "<=>")1553615536
rc = compile_expr_gc_rooted(recv)1553715537
cmp_call = "sp_" + cmp_owner + "__cmp(" + rc + ", " + ca + ")"15538+
# Promote mode: <=> returns sp_Bigint*. Unbox via sp_bigint_to_int15539+
# so the < / > / <= / >= comparison fires on the int value, not15540+
# on the heap pointer (which would compare against 0 = "is NULL?").15541+
cmp_ret = cls_method_return(find_class_idx(cmp_owner), "<=>")15542+
if base_type(cmp_ret) == "bigint"15543+
@needs_bigint = 115544+
cmp_call = "sp_bigint_to_int((sp_Bigint *)" + cmp_call + ")"15545+
end1553815546
if mname == "<"1553915547
return "(" + cmp_call + " < 0)"1554015548
end