Commit 6e8ec062

6e8ec062f0d4Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 1 file · ~1 modified

Description

fix(codegen): IntArray#sort_by block-tail unboxes bigint to mrb_int key

The bubble-sort emit for int_array.sort_by { ... } materialized the block tail into mrb_int _ka / mrb_int _kb keys for the swap comparison. A promote-widened block tail (e.g. arr.sort_by { |x| -x } where the negation now yields bigint) tripped the init's type mismatch.

Snapshot the block-tail's inferred type and route through sp_bigint_to_int when bigint before assigning to the mrb_int key.

Promote-mode test count: 530 / 50 / 38 (no test-count change but the warning is now clean for sort_by paths). Default raise mode unchanged at 618 / 0 / 0.

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

Details

Commit
6e8ec062f0d4
Parent
b9c8e85c4745

spinel_codegen.rbmodifiedView file

@@ -18004,15 +18004,26 @@
1800418004 emit(" mrb_int lv_" + bp + " = " + tmp + "->data[" + tmp + "->start + _j];")
1800518005 bbody = @nd_body[blk]
1800618006 bexpr = "0"
18007+ bexpr_t_sb = "int"
1800718008 if bbody >= 0
1800818009 bs = get_stmts(bbody)
1800918010 if bs.length > 0
1801018011 bexpr = compile_expr(bs.last)
18012+ bexpr_t_sb = infer_type(bs.last)
1801118013 end
1801218014 end
18013- emit(" mrb_int _ka = " + bexpr + ";")
18015+ ka_init_sb = bexpr
18016+ if bexpr_t_sb == "bigint"
18017+ @needs_bigint = 1
18018+ ka_init_sb = "sp_bigint_to_int((sp_Bigint *)" + bexpr + ")"
18019+ end
18020+ emit(" mrb_int _ka = " + ka_init_sb + ";")
1801418021 emit(" lv_" + bp + " = " + tmp + "->data[" + tmp + "->start + _j + 1];")
18015- emit(" mrb_int _kb = " + bexpr + ";")
18022+ kb_init_sb = bexpr
18023+ if bexpr_t_sb == "bigint"
18024+ kb_init_sb = "sp_bigint_to_int((sp_Bigint *)" + bexpr + ")"
18025+ end
18026+ emit(" mrb_int _kb = " + kb_init_sb + ";")
1801618027 emit(" if (_ka > _kb) { mrb_int _t = " + tmp + "->data[" + tmp + "->start + _j]; " + tmp + "->data[" + tmp + "->start + _j] = " + tmp + "->data[" + tmp + "->start + _j + 1]; " + tmp + "->data[" + tmp + "->start + _j + 1] = _t; }")
1801718028 emit(" }")
1801818029 emit(" }")