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

@@ -21922,11 +21922,26 @@
2192221922 slot_expr_cm = ""
2192321923 if pos_idx_cm < positional_cm.length
2192421924 # Route through compile_expr_for_expected_type when the
21925- # slot's declared type needs an int<->bigint cast (promote
21926- # mode often promotes the param while the call site still
21927- # passes a literal int / int-typed local).
21925+ # slot's declared type needs a coercion: int<->bigint
21926+ # promote mode, OR when arg type and param type disagree
21927+ # in a way the helper can bridge (poly->concrete unbox via
21928+ # tag-field, concrete->poly box, etc.). #685 surfaces this
21929+ # whenever an sp_RbVal ivar flows into a typed-hash /
21930+ # typed-obj / mrb_int callee param.
2192821931 slot_pt_pos_cm = kk < owner_pt.length ? owner_pt[kk] : ""
21929- if slot_pt_pos_cm != "" && (base_type(slot_pt_pos_cm) == "bigint" || base_type(slot_pt_pos_cm) == "int")
21932+ at_pos_cm = infer_type(positional_cm[pos_idx_cm])
21933+ slot_pt_base_cm = base_type(slot_pt_pos_cm)
21934+ needs_coerce_cm = 0
21935+ if slot_pt_pos_cm != ""
21936+ if slot_pt_base_cm == "bigint" || slot_pt_base_cm == "int"
21937+ needs_coerce_cm = 1
21938+ elsif at_pos_cm == "poly" && slot_pt_base_cm != "poly" && slot_pt_base_cm != ""
21939+ needs_coerce_cm = 1
21940+ elsif at_pos_cm != "poly" && slot_pt_base_cm == "poly"
21941+ needs_coerce_cm = 1
21942+ end
21943+ end
21944+ if needs_coerce_cm == 1
2193021945 slot_expr_cm = compile_expr_for_expected_type(positional_cm[pos_idx_cm], slot_pt_pos_cm)
2193121946 else
2193221947 slot_expr_cm = cast_away_volatile_arg(positional_cm[pos_idx_cm], compile_expr(positional_cm[pos_idx_cm]))