Commit 4e1c20d6
4e1c20d60507Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 1 file · ~1 modified
Description
fix(codegen): cls method call args coerce poly/concrete mismatches
For <Class>.<cmethod>(args) call sites, the positional arg arm
only routed through compile_expr_for_expected_type when the param
type was bigint/int (promote-mode bridge). Other coercions slipped
through: an sp_RbVal ivar passed to a typed-hash / mrb_int callee
param, or an mrb_int ivar passed to an sp_RbVal-declared callee
param, all came out as raw assignments and tripped clang's
incompatible-type errors.
Extend the routing: also call compile_expr_for_expected_type when the arg's static type is poly and the callee param is concrete (non-poly), or when the arg is concrete and the param is poly. compile_expr_for_expected_type already handles both directions via box_value_to_poly / .v.X unbox helpers; the only missing piece was getting the call site to route there.
Tests: default 460/0/0, promote 460/0/0, optcarrot checksum 59662.
#685: 5 hard errors -> 2 remaining. The two remainders (sp_ActionResponse_new with sp_RbVal args; sp_Article_cls_ _adapter_exists_by_id_p with sp_RbVal arg inside another cls method body) go through different lowering paths (compile_constructor_args, bare cls-call-in-cls-body) and need their own coerce-routing fixes.
Refs #685
Co-Authored-By: Claude Opus 4.7 [email protected]
Details
- Commit
- 4e1c20d60507
- Parent
- 85e22fcba902
spinel_codegen.rbmodifiedView file
slot_expr_cm = "" if pos_idx_cm < positional_cm.length # Route through compile_expr_for_expected_type when the # slot's declared type needs an int<->bigint cast (promote # mode often promotes the param while the call site still # passes a literal int / int-typed local). # slot's declared type needs a coercion: int<->bigint # promote mode, OR when arg type and param type disagree # in a way the helper can bridge (poly->concrete unbox via # tag-field, concrete->poly box, etc.). #685 surfaces this # whenever an sp_RbVal ivar flows into a typed-hash / # typed-obj / mrb_int callee param. slot_pt_pos_cm = kk < owner_pt.length ? owner_pt[kk] : "" if slot_pt_pos_cm != "" && (base_type(slot_pt_pos_cm) == "bigint" || base_type(slot_pt_pos_cm) == "int") at_pos_cm = infer_type(positional_cm[pos_idx_cm]) slot_pt_base_cm = base_type(slot_pt_pos_cm) needs_coerce_cm = 0 if slot_pt_pos_cm != "" if slot_pt_base_cm == "bigint" || slot_pt_base_cm == "int" needs_coerce_cm = 1 elsif at_pos_cm == "poly" && slot_pt_base_cm != "poly" && slot_pt_base_cm != "" needs_coerce_cm = 1 elsif at_pos_cm != "poly" && slot_pt_base_cm == "poly" needs_coerce_cm = 1 end end if needs_coerce_cm == 1 slot_expr_cm = compile_expr_for_expected_type(positional_cm[pos_idx_cm], slot_pt_pos_cm) else slot_expr_cm = cast_away_volatile_arg(positional_cm[pos_idx_cm], compile_expr(positional_cm[pos_idx_cm]))