Commit b9c8e85c

b9c8e85c4745Merged

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

Description

fix(codegen): kwarg arg coerces int<->bigint to declared param type

compile_call_args_with_defaults matched kwargs to params by name and emitted the raw kw_vals[ki] against the declared slot type (except for the poly arm). With promote mode widening a numeric kwarg's param to bigint (def truncate(s, length, suffix); end called as M.truncate(s, length: 100)), the int literal flowed into a sp_Bigint * slot unwrapped.

Coerce via sp_bigint_new_int / sp_bigint_to_int when the inferred kw arg type and the declared param type disagree across the int <-> bigint boundary.

Promote-mode test count: 529 pass / 50 fail / 39 error -> 530 pass / 50 fail / 38 error. Default raise mode unchanged at 618 / 0 / 0.

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

Details

Commit
b9c8e85c4745
Parent
2bcdb4b43e01

spinel_codegen.rbmodifiedView file

@@ -23311,7 +23311,18 @@
2331123311 # that flows non-string objs through here.
2331223312 result = result + box_expr_to_poly(kw_arg_ids[ki])
2331323313 else
23314- result = result + kw_vals[ki]
23314+ # promote-mode coerce: kw value's static type vs
23315+ # param's declared type may need int <-> bigint.
23316+ kw_val_pft = kw_vals[ki]
23317+ kw_arg_t_pft = ki < kw_arg_ids.length ? infer_type(kw_arg_ids[ki]) : ""
23318+ if base_type(ptypes[k]) == "bigint" && kw_arg_t_pft == "int"
23319+ @needs_bigint = 1
23320+ kw_val_pft = "sp_bigint_new_int(" + kw_val_pft + ")"
23321+ elsif base_type(ptypes[k]) == "int" && kw_arg_t_pft == "bigint"
23322+ @needs_bigint = 1
23323+ kw_val_pft = "sp_bigint_to_int((sp_Bigint *)" + kw_val_pft + ")"
23324+ end
23325+ result = result + kw_val_pft
2331523326 end
2331623327 else
2331723328 result = result + kw_vals[ki]