Commit 87bc59b8

87bc59b8d6b5Merged

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

Description

fix(codegen): inlined yield expr-form coerces tail + declares original local

compile_yield_call_expr declared the renamed _yN locals in scope but not the original names, so find_var_type inside the inlined body returned "" for an unrenamed AST read and missed the promote-mode bigint slot type.

Also coerce the last-expression value when its inferred type differs from the declared return type (bigint <-> int) — a literal-int tail like 42 against a bigint return slot now wraps through sp_bigint_new_int.

Promote-mode test count: 519 pass / 49 fail / 50 error -> 520 pass / 49 fail / 49 error. Default raise mode unchanged at 618 / 0 / 0.

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

Details

Commit
87bc59b8d6b5
Parent
9c714398c5e6

spinel_codegen.rbmodifiedView file

@@ -34638,6 +34638,11 @@
3463834638 param_map_from.push(flocals_n[kf])
3463934639 param_map_to.push(tname)
3464034640 declare_var(tname, flocals_t[kf])
34641+ # Also expose the original name so find_var_type lookups in
34642+ # the inlined body (which sees the unrenamed AST node) find
34643+ # the right type — mirrors compile_yield_call_stmt /
34644+ # compile_yield_method_call_stmt.
34645+ declare_var(flocals_n[kf], flocals_t[kf])
3464134646 kf = kf + 1
3464234647 end
3464334648 end
@@ -34668,7 +34673,16 @@
3466834673 compile_stmt_with_block(last_y, blk, bp_names, param_map_from, param_map_to)
3466934674 else
3467034675 # Expression-shaped: capture the value via compile_expr_remap.
34671- emit(" " + result_tmp + " = " + compile_expr_remap(last_y, param_map_from, param_map_to) + ";")
34676+ last_val_yc = compile_expr_remap(last_y, param_map_from, param_map_to)
34677+ last_t_yc = infer_type(last_y)
34678+ if base_type(rt_yc) == "bigint" && last_t_yc == "int"
34679+ @needs_bigint = 1
34680+ last_val_yc = "sp_bigint_new_int(" + last_val_yc + ")"
34681+ elsif base_type(rt_yc) == "int" && last_t_yc == "bigint"
34682+ @needs_bigint = 1
34683+ last_val_yc = "sp_bigint_to_int((sp_Bigint *)" + last_val_yc + ")"
34684+ end
34685+ emit(" " + result_tmp + " = " + last_val_yc + ";")
3467234686 end
3467334687 end
3467434688 end