Commit 9f6587ba
9f6587ba9e30Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 2 files · +1 added · ~1 modified
Description
Merge pull request #252 from mame/pr/poly-dispatch-arity-truncate
fix(codegen): truncate extra args in poly-dispatch arms
Details
- Commit
- 9f6587ba9e30
- Parent
- 9694d0f25c04
- Merge parent
- bc14d9772da5
spinel_codegen.rbmodifiedView file
@@ -22515,25 +22515,30 @@
2251522515
cname = @cls_names[i]2251622516
midx = cls_find_method_direct(i, mname)2251722517
if midx >= 022518-
# Pad with default-typed zeros when target method has more22519-
# params than the call site supplied — same shape that C22520-
# demands at every fixed-arity call. Per-arm padding lets us22521-
# poly-dispatch `recv.m()` even when one of the candidate22522-
# classes has a method that takes positional defaults.22523-
arm_arg_strs = arg_strs22518+
# Match each arm to the target method's *fixed* C arity:22519+
# pad missing trailing slots with default-typed zeros, and22520+
# truncate extras (when the call site supplies more args than22521+
# this candidate accepts — happens when several classes share22522+
# the method name but disagree on parameter count).22523+
arm_arg_strs = ""2252422524
all_ptypes = @cls_meth_ptypes[i].split("|")22525+
arm_ptypes = "".split(",")2252522526
if midx < all_ptypes.length2252622527
arm_ptypes = all_ptypes[midx].split(",")22527-
pk = arg_compiled.length22528-
while pk < arm_ptypes.length22528+
end22529+
pk = 022530+
while pk < arm_ptypes.length22531+
if pk < arg_compiled.length22532+
arm_arg_strs = arm_arg_strs + ", " + arg_compiled[pk]22533+
else2252922534
pad = "0"2253022535
pt_base = base_type(arm_ptypes[pk])2253122536
if pt_base == "poly"2253222537
pad = "sp_box_nil()"2253322538
end2253422539
arm_arg_strs = arm_arg_strs + ", " + pad22535-
pk = pk + 12253622540
end22541+
pk = pk + 12253722542
end2253822543
call_expr = "sp_" + cname + "_" + sanitize_name(mname) + "((sp_" + cname + " *)" + recv_tmp + ".v.p" + arm_arg_strs + ")"2253922544
rhs = call_exprtest/poly_dispatch_arity_truncate.rbaddedView file
Loading diff…