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
pk = 0 while pk < arm_ptypes.length if pk < arg_compiled.length arm_arg_strs = arm_arg_strs + ", " + arg_compiled[pk] # Issue #351: when this arm's param widened to `poly` # (matz/spinel#341 cross-call-site union) but the call # site supplied a concrete value (string / mrb_int / # symbol / ...), box it via the appropriate sp_box_* # helper. Without this, gcc errors `incompatible type # for argument` — `const char *` / `mrb_int` into a # `sp_RbVal` slot. Inverse direction (poly arg into a # concrete-typed param) was already covered downstream; # this only handles the boxing direction. arg_v = arg_compiled[pk] arm_pt_base = base_type(arm_ptypes[pk]) if arm_pt_base == "poly" && pk < arg_types.length && arg_types[pk] != "poly" && arg_types[pk] != "" arg_v = box_value_to_poly(arg_types[pk], arg_v) end arm_arg_strs = arm_arg_strs + ", " + arg_v else pad = "0" pt_base = base_type(arm_ptypes[pk])test/poly_recv_aref_box_arm.rbaddedView file
Loading diff…
test/poly_recv_aref_box_arm.rb.expectedaddedView file
Loading diff…