Commit b498aea6

b498aea6aba1Merged

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

Description

fix(codegen): method-level rescue body coerces int<->bigint into result tmp

compile_body_into (the helper used by method-level BeginNode + rescue paths to capture the begin / rescue tail into ret_tmp) emitted ret_tmp = compile_expr(last); without coercing. A promote-mode method whose declared return is bigint and whose rescue body returns -1 produced _t1 = -1LL; against a bigint slot.

Coerce in both directions when the inferred last-expression type doesn't match return_type's base. compile_rescue_chain_into reuses compile_body_into recursively, so the fix covers both the begin arm and each rescue arm.

Promote-mode test count: 524 pass / 49 fail / 45 error -> 526 pass / 49 fail / 43 error. Default raise mode unchanged at 618 / 0 / 0.

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

Details

Commit
b498aea6aba1
Parent
ed79989191a8

spinel_codegen.rbmodifiedView file

@@ -35752,6 +35752,14 @@
3575235752 end
3575335753 end
3575435754 expr = compile_expr(last)
35755+ last_t_cbi = infer_type(last)
35756+ if base_type(return_type) == "bigint" && last_t_cbi == "int"
35757+ @needs_bigint = 1
35758+ expr = "sp_bigint_new_int(" + expr + ")"
35759+ elsif base_type(return_type) == "int" && last_t_cbi == "bigint"
35760+ @needs_bigint = 1
35761+ expr = "sp_bigint_to_int((sp_Bigint *)" + expr + ")"
35762+ end
3575535763 emit(" " + ret_tmp + " = " + expr + ";")
3575635764 end
3575735765