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
end if rt == "str_int_hash" tmp = new_temp bp2_ot_si = bp2 != "" ? find_var_type(bp2) : "" emit(" for (mrb_int " + tmp + " = 0; " + tmp + " < " + rc + "->len; " + tmp + "++) {") emit(" lv_" + bp1 + " = " + rc + "->order[" + tmp + "];") if bp2 != "" push_scope declare_var(bp1, "string") if bp2 != "" declare_var(bp2, "int") declare_var(bp2, bp2_ot_si == "bigint" ? "bigint" : "int") end redo_label = push_redo_label emit_redo_label(redo_label) end if rt == "int_str_hash" tmp = new_temp bp1_ot_is = find_var_type(bp1) emit(" for (mrb_int " + tmp + " = 0; " + tmp + " < " + rc + "->len; " + tmp + "++) {") emit_block_lv_assign_int(bp1, rc + "->order[" + tmp + "]") if bp2 != "" end @indent = @indent + 1 push_scope declare_var(bp1, "int") declare_var(bp1, bp1_ot_is == "bigint" ? "bigint" : "int") if bp2 != "" declare_var(bp2, "string") end end if rt == "sym_int_hash" tmp = new_temp bp2_ot_sy = bp2 != "" ? find_var_type(bp2) : "" emit(" for (mrb_int " + tmp + " = 0; " + tmp + " < " + rc + "->len; " + tmp + "++) {") emit(" lv_" + bp1 + " = " + rc + "->order[" + tmp + "];") if bp2 != "" push_scope declare_var(bp1, "symbol") if bp2 != "" declare_var(bp2, "int") declare_var(bp2, bp2_ot_sy == "bigint" ? "bigint" : "int") end redo_label = push_redo_label emit_redo_label(redo_label)