Commit 8d3731c7

8d3731c74d4aMerged

Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 3 files · +2 added · ~1 modified

Description

fix(codegen): poly-recv [] arm boxes concrete arg into widened-poly param

Sister fix to #341. After d697705 widened a user class's def [](k) param to sp_RbVal when callers across the program disagreed on key type (one passes String, another passes Symbol), compile_poly_method_call's per-class dispatch arm emit passed the raw call-site value to the now-poly slot. C errored incompatible type for argument 2 of 'sp_<C>__aref' — const char * / mrb_int / etc. into a sp_RbVal parameter.

Fix: when the arm's ptype base is poly but the call-site arg's static type is concrete, wrap the compiled arg expression in box_value_to_poly(arg_type, val) so the arm receives a pre-boxed sp_RbVal that matches the slot.

Surfaced via Roundhouse's view-helper shape def field_for(model, field); model[field]; end where model is poly{Article, Comment, HWIA, Parameters} and field is Symbol — 7 errors per emitted test of the mrb_int → sp_RbVal flavor; 20+ errors in real-blog main for the same shape across views.

Fixes #351

Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]

Details

Commit
8d3731c74d4a
Parent
01f36bc8ec7a

spinel_codegen.rbmodifiedView file

@@ -26764,7 +26764,21 @@
2676426764 pk = 0
2676526765 while pk < arm_ptypes.length
2676626766 if pk < arg_compiled.length
26767- arm_arg_strs = arm_arg_strs + ", " + arg_compiled[pk]
26767+ # Issue #351: when this arm's param widened to `poly`
26768+ # (matz/spinel#341 cross-call-site union) but the call
26769+ # site supplied a concrete value (string / mrb_int /
26770+ # symbol / ...), box it via the appropriate sp_box_*
26771+ # helper. Without this, gcc errors `incompatible type
26772+ # for argument` — `const char *` / `mrb_int` into a
26773+ # `sp_RbVal` slot. Inverse direction (poly arg into a
26774+ # concrete-typed param) was already covered downstream;
26775+ # this only handles the boxing direction.
26776+ arg_v = arg_compiled[pk]
26777+ arm_pt_base = base_type(arm_ptypes[pk])
26778+ if arm_pt_base == "poly" && pk < arg_types.length && arg_types[pk] != "poly" && arg_types[pk] != ""
26779+ arg_v = box_value_to_poly(arg_types[pk], arg_v)
26780+ end
26781+ arm_arg_strs = arm_arg_strs + ", " + arg_v
2676826782 else
2676926783 pad = "0"
2677026784 pt_base = base_type(arm_ptypes[pk])