Commit 2e7debe5

2e7debe55de3Merged

Dmitry Bochkarev <[email protected]> · 6 months ago · 1 file · ~1 modified

Description

fix: inherited method dispatch in poly call lowering

Details

Commit
2e7debe55de3
Parent
0aadbcf4dde1

spinel_codegen.rbmodifiedView file

@@ -18393,6 +18393,16 @@
1839318393 while i < @cls_names.length
1839418394 cname = @cls_names[i]
1839518395 midx = cls_find_method_direct(i, mname)
18396+ owner_idx = i
18397+ if midx < 0
18398+ owner_name = find_method_owner(i, mname)
18399+ if owner_name != ""
18400+ owner_idx = find_class_idx(owner_name)
18401+ if owner_idx >= 0
18402+ midx = cls_find_method_direct(owner_idx, mname)
18403+ end
18404+ end
18405+ end
1839618406 if midx >= 0
1839718407 # Match each arm to the target method's *fixed* C arity:
1839818408 # pad missing trailing slots with default-typed zeros, and
@@ -18400,7 +18410,7 @@
1840018410 # this candidate accepts — happens when several classes share
1840118411 # the method name but disagree on parameter count).
1840218412 arm_arg_strs = ""
18403- arm_ptypes = cls_meth_ptypes_get(i, midx)
18413+ arm_ptypes = cls_meth_ptypes_get(owner_idx, midx)
1840418414 pk = 0
1840518415 while pk < arm_ptypes.length
1840618416 if pk < arg_compiled.length
@@ -18452,10 +18462,10 @@
1845218462 end
1845318463 pk = pk + 1
1845418464 end
18455- call_expr = "sp_" + cname + "_" + sanitize_name(mname) + "((sp_" + cname + " *)" + recv_tmp + ".v.p" + arm_arg_strs + ")"
18465+ call_expr = "sp_" + @cls_names[owner_idx] + "_" + sanitize_name(mname) + "((sp_" + @cls_names[owner_idx] + " *)" + recv_tmp + ".v.p" + arm_arg_strs + ")"
1845618466 rhs = call_expr
1845718467 if is_poly_ret == 1
18458- this_rt = cls_method_return(i, mname)
18468+ this_rt = cls_method_return(owner_idx, mname)
1845918469 rhs = box_val_to_poly(call_expr, this_rt)
1846018470 end
1846118471 # Narrowed `[]` arms (Approach 2): suppress user-class arms
@@ -18463,7 +18473,7 @@
1846318473 # otherwise assign e.g. a string to the now-mrb_int result
1846418474 # temp and fail the C compile. The runtime can't reach these
1846518475 # arms anyway because the observation set narrowed past them.
18466- if narrowed_int_idx == 1 && cls_method_return(i, mname) != "int"
18476+ if narrowed_int_idx == 1 && cls_method_return(owner_idx, mname) != "int"
1846718477 # skip
1846818478 else
1846918479 emit(" if (" + recv_tmp + ".cls_id == " + cls_id_for_user_internal(i).to_s + ") " + tmp + " = " + rhs + ";")