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 >= 0
21888- 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 more
21889+ # params than the call site supplied — same shape that C
21890+ # demands at every fixed-arity call. Per-arm padding lets us
21891+ # poly-dispatch `recv.m()` even when one of the candidate
21892+ # classes has a method that takes positional defaults.
21893+ arm_arg_strs = arg_strs
21894+ all_ptypes = @cls_meth_ptypes[i].split("|")
21895+ if midx < all_ptypes.length
21896+ arm_ptypes = all_ptypes[midx].split(",")
21897+ pk = arg_compiled.length
21898+ while pk < arm_ptypes.length
21899+ pad = "0"
21900+ pt_base = base_type(arm_ptypes[pk])
21901+ if pt_base == "poly"
21902+ pad = "sp_box_nil()"
21903+ end
21904+ arm_arg_strs = arm_arg_strs + ", " + pad
21905+ pk = pk + 1
21906+ end
21907+ end
21908+ call_expr = "sp_" + cname + "_" + sanitize_name(mname) + "((sp_" + cname + " *)" + recv_tmp + ".v.p" + arm_arg_strs + ")"
2188921909 rhs = call_expr
2189021910 if is_poly_ret == 1
2189121911 this_rt = cls_method_return(i, mname)