Commit 386c4ba3
386c4ba362bcMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 2 files · +1 added · ~1 modified
Description
Merge pull request #243 from mame/pr/poly-dispatch-arity-padding
fix(codegen): pad missing positional args in poly-dispatch arms
Details
- Commit
- 386c4ba362bc
- Parent
- 300441b5bc36
- Merge parent
- 71c12b5ff39f
spinel_codegen.rbmodifiedView file
@@ -21885,7 +21885,27 @@
2188521885
cname = @cls_names[i]2188621886
midx = cls_find_method_direct(i, mname)2188721887
if midx >= 021888-
call_expr = "sp_" + cname + "_" + sanitize_name(mname) + "((sp_" + cname + " *)" + recv_tmp + ".v.p" + arg_strs + ")"21888+
# Pad with default-typed zeros when target method has more21889+
# params than the call site supplied — same shape that C21890+
# demands at every fixed-arity call. Per-arm padding lets us21891+
# poly-dispatch `recv.m()` even when one of the candidate21892+
# classes has a method that takes positional defaults.21893+
arm_arg_strs = arg_strs21894+
all_ptypes = @cls_meth_ptypes[i].split("|")21895+
if midx < all_ptypes.length21896+
arm_ptypes = all_ptypes[midx].split(",")21897+
pk = arg_compiled.length21898+
while pk < arm_ptypes.length21899+
pad = "0"21900+
pt_base = base_type(arm_ptypes[pk])21901+
if pt_base == "poly"21902+
pad = "sp_box_nil()"21903+
end21904+
arm_arg_strs = arm_arg_strs + ", " + pad21905+
pk = pk + 121906+
end21907+
end21908+
call_expr = "sp_" + cname + "_" + sanitize_name(mname) + "((sp_" + cname + " *)" + recv_tmp + ".v.p" + arm_arg_strs + ")"2188921909
rhs = call_expr2189021910
if is_poly_ret == 12189121911
this_rt = cls_method_return(i, mname)test/poly_dispatch_arity_padding.rbaddedView file
Loading diff…