Commit 7f4aabe1

7f4aabe11729Merged

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

Description

fix(codegen): inlined yield function locals declare original name too

compile_yield_method_call_stmt declared the renamed _yN local in scope but not the original name. Body emit goes through compile_expr_remap which:

  • maps the LV-read's emitted text to lv_i_y1 (renamed)
  • but consults find_var_type by the unrenamed AST name "i"

Without the original-name declare, find_var_type("i") returned "" and infer_type fell back to "int", so a while i < @nums.length inside the inlined body never dispatched through the bigint arithmetic arm and emitted (lv_i_y1 < sp_IntArray_length(...)) with a pointer/int mismatch.

Also unbox the index in compile_expr_remap's int_array / float_ array [] arm when the index is bigint-typed, so the inlined @nums[i] emit reaches sp_IntArray_get with a clean mrb_int subscript.

Promote-mode test count: 516 pass / 48 fail / 54 error -> 518 pass / 48 fail / 52 error. Default raise mode unchanged at 618 / 0 / 0.

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

Details

Commit
7f4aabe11729
Parent
4dfadf3d5f26

spinel_codegen.rbmodifiedView file

@@ -34498,6 +34498,10 @@
3449834498 param_map_from.push(flocals_n[k])
3449934499 param_map_to.push(tname)
3450034500 declare_var(tname, flocals_t[k])
34501+ # Also expose the original local name so the body emit's
34502+ # find_var_type lookup (via the unrenamed AST node) returns
34503+ # the right type. Mirrors the param declare pair above.
34504+ declare_var(flocals_n[k], flocals_t[k])
3450134505 k = k + 1
3450234506 end
3450334507 end
@@ -35061,10 +35065,28 @@
3506135065 end
3506235066 if rt_r == "int_array" && mname == "[]"
3506335067 arg_r = compile_expr_remap_arg0(nid, map_from, map_to)
35068+ # Unbox bigint index — promote mode may have widened the
35069+ # iter counter local to sp_Bigint *.
35070+ args_id_ir = @nd_arguments[nid]
35071+ if args_id_ir >= 0
35072+ aa_ir = get_args(args_id_ir)
35073+ if aa_ir.length > 0 && infer_type(aa_ir[0]) == "bigint"
35074+ @needs_bigint = 1
35075+ arg_r = "sp_bigint_to_int((sp_Bigint *)" + arg_r + ")"
35076+ end
35077+ end
3506435078 return "sp_IntArray_get(" + rc_r + ", " + arg_r + ")"
3506535079 end
3506635080 if rt_r == "float_array" && mname == "[]"
3506735081 arg_r = compile_expr_remap_arg0(nid, map_from, map_to)
35082+ args_id_fr = @nd_arguments[nid]
35083+ if args_id_fr >= 0
35084+ aa_fr = get_args(args_id_fr)
35085+ if aa_fr.length > 0 && infer_type(aa_fr[0]) == "bigint"
35086+ @needs_bigint = 1
35087+ arg_r = "sp_bigint_to_int((sp_Bigint *)" + arg_r + ")"
35088+ end
35089+ end
3506835090 return "sp_FloatArray_get(" + rc_r + ", " + arg_r + ")"
3506935091 end
3507035092 if (rt_r == "str_array" || rt_r == "int_array" || rt_r == "sym_array") && (mname == "length" || mname == "size")