Commit 71c12b5f
71c12b5ff39fMerged
Yusuke Endoh <[email protected]> · 6 months ago · 2 files · +1 added · ~1 modified
Description
fix(codegen): pad missing positional args in poly-dispatch arms
When recv.m(...) is compiled with a poly receiver, the dispatch
emits one C-call arm per user class that defines m. Each arm has
to match its target's fixed C arity, which can differ from the
call site's argument count when one of the candidate methods takes
positional defaults. Without padding, the C compiler rejects the
table with too few arguments to function 'sp_<Class>_<m>' even
though the runtime cls_id check would skip that arm.
Pad the missing trailing slots with default-typed zeros (0 for
non-poly param types, sp_box_nil() for poly) so each arm compiles
regardless of which other class's method dictates the column.
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- 71c12b5ff39f
- Parent
- 15f7e5f356d7
spinel_codegen.rbmodifiedView file
cname = @cls_names[i] midx = cls_find_method_direct(i, mname) if midx >= 0 call_expr = "sp_" + cname + "_" + sanitize_name(mname) + "((sp_" + cname + " *)" + recv_tmp + ".v.p" + arg_strs + ")" # Pad with default-typed zeros when target method has more # params than the call site supplied — same shape that C # demands at every fixed-arity call. Per-arm padding lets us # poly-dispatch `recv.m()` even when one of the candidate # classes has a method that takes positional defaults. arm_arg_strs = arg_strs all_ptypes = @cls_meth_ptypes[i].split("|") if midx < all_ptypes.length arm_ptypes = all_ptypes[midx].split(",") pk = arg_compiled.length while pk < arm_ptypes.length pad = "0" pt_base = base_type(arm_ptypes[pk]) if pt_base == "poly" pad = "sp_box_nil()" end arm_arg_strs = arm_arg_strs + ", " + pad pk = pk + 1 end end call_expr = "sp_" + cname + "_" + sanitize_name(mname) + "((sp_" + cname + " *)" + recv_tmp + ".v.p" + arm_arg_strs + ")" rhs = call_expr if is_poly_ret == 1 this_rt = cls_method_return(i, mname)test/poly_dispatch_arity_padding.rbaddedView file
Loading diff…