Commit 9a62e12b

9a62e12b70f5Merged

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

Description

fix(codegen): hash#each block-param scope type follows promoted outer slot

compile_each_block's str_int_hash / int_str_hash / sym_int_hash arms declared the int-typed key or value as int in the block- inner scope. With promote mode widening the outer LV to bigint, the block body then read the var as int and lowered .to_s / arithmetic to sp_int_to_s(bigint_ptr) -- wrong both at the C type level and semantically.

Snapshot the outer-scope slot type via find_var_type before push_scope; if it's bigint, declare the block-scope var as bigint too. The emit_block_lv_assign_int helper already wraps the int rhs through sp_bigint_new_int so the slot stays consistent.

Promote-mode test count: 494 pass / 43 fail / 81 error -> 497 pass / 43 fail / 78 error. Default raise mode unchanged at 618 / 0 / 0.

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

Details

Commit
9a62e12b70f5
Parent
5001c4964b01

spinel_codegen.rbmodifiedView file

@@ -31526,6 +31526,7 @@
3152631526 end
3152731527 if rt == "str_int_hash"
3152831528 tmp = new_temp
31529+ bp2_ot_si = bp2 != "" ? find_var_type(bp2) : ""
3152931530 emit(" for (mrb_int " + tmp + " = 0; " + tmp + " < " + rc + "->len; " + tmp + "++) {")
3153031531 emit(" lv_" + bp1 + " = " + rc + "->order[" + tmp + "];")
3153131532 if bp2 != ""
@@ -31535,7 +31536,7 @@
3153531536 push_scope
3153631537 declare_var(bp1, "string")
3153731538 if bp2 != ""
31538- declare_var(bp2, "int")
31539+ declare_var(bp2, bp2_ot_si == "bigint" ? "bigint" : "int")
3153931540 end
3154031541 redo_label = push_redo_label
3154131542 emit_redo_label(redo_label)
@@ -31547,6 +31548,7 @@
3154731548 end
3154831549 if rt == "int_str_hash"
3154931550 tmp = new_temp
31551+ bp1_ot_is = find_var_type(bp1)
3155031552 emit(" for (mrb_int " + tmp + " = 0; " + tmp + " < " + rc + "->len; " + tmp + "++) {")
3155131553 emit_block_lv_assign_int(bp1, rc + "->order[" + tmp + "]")
3155231554 if bp2 != ""
@@ -31554,7 +31556,7 @@
3155431556 end
3155531557 @indent = @indent + 1
3155631558 push_scope
31557- declare_var(bp1, "int")
31559+ declare_var(bp1, bp1_ot_is == "bigint" ? "bigint" : "int")
3155831560 if bp2 != ""
3155931561 declare_var(bp2, "string")
3156031562 end
@@ -31589,6 +31591,7 @@
3158931591 end
3159031592 if rt == "sym_int_hash"
3159131593 tmp = new_temp
31594+ bp2_ot_sy = bp2 != "" ? find_var_type(bp2) : ""
3159231595 emit(" for (mrb_int " + tmp + " = 0; " + tmp + " < " + rc + "->len; " + tmp + "++) {")
3159331596 emit(" lv_" + bp1 + " = " + rc + "->order[" + tmp + "];")
3159431597 if bp2 != ""
@@ -31598,7 +31601,7 @@
3159831601 push_scope
3159931602 declare_var(bp1, "symbol")
3160031603 if bp2 != ""
31601- declare_var(bp2, "int")
31604+ declare_var(bp2, bp2_ot_sy == "bigint" ? "bigint" : "int")
3160231605 end
3160331606 redo_label = push_redo_label
3160431607 emit_redo_label(redo_label)