Commit 96ff6a83
96ff6a83b049Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 7 files · +6 added · ~1 modified
Description
Merge pull request #469 from DmitryBochkarev/fix/poly_inherithed_methods
Fix poly inherithed methods
Details
- Commit
- 96ff6a83b049
- Parent
- f2ddceb91fdb
- Merge parent
- ea80598202f6
spinel_codegen.rbmodifiedView file
@@ -17864,6 +17864,12 @@
1786417864
end1786517865
j = j + 11786617866
end17867+
if @cls_parents[ci] != ""17868+
pi = find_class_idx(@cls_parents[ci])17869+
if pi >= 017870+
return cls_has_attr_reader(pi, mname)17871+
end17872+
end1786717873
01786817874
end1786917875
@@ -18116,7 +18122,7 @@
1811618122
ci_s = 01811718123
diverges = 01811818124
while ci_s < @cls_names.length18119-
if cls_find_method_direct(ci_s, mname) >= 018125+
if cls_find_method(ci_s, mname) >= 01812018126
urt = cls_method_return(ci_s, mname)1812118127
if urt != "" && urt != "string"1812218128
diverges = 1@@ -18144,7 +18150,7 @@
1814418150
ci = 01814518151
while ci < @cls_names.length1814618152
rt = ""18147-
if cls_find_method_direct(ci, mname) >= 018153+
if cls_find_method(ci, mname) >= 01814818154
rt = cls_method_return(ci, mname)1814918155
elsif cls_has_attr_reader(ci, mname) == 11815018156
# An attr_reader returns the ivar type. .@@ -18417,6 +18423,16 @@
1841718423
while i < @cls_names.length1841818424
cname = @cls_names[i]1841918425
midx = cls_find_method_direct(i, mname)18426+
owner_idx = i18427+
if midx < 018428+
owner_name = find_method_owner(i, mname)18429+
if owner_name != ""18430+
owner_idx = find_class_idx(owner_name)18431+
if owner_idx >= 018432+
midx = cls_find_method_direct(owner_idx, mname)18433+
end18434+
end18435+
end1842018436
if midx >= 01842118437
# Match each arm to the target method's *fixed* C arity:1842218438
# pad missing trailing slots with default-typed zeros, and@@ -18424,7 +18440,7 @@
1842418440
# this candidate accepts — happens when several classes share1842518441
# the method name but disagree on parameter count).1842618442
arm_arg_strs = ""18427-
arm_ptypes = cls_meth_ptypes_get(i, midx)18443+
arm_ptypes = cls_meth_ptypes_get(owner_idx, midx)1842818444
pk = 01842918445
while pk < arm_ptypes.length1843018446
if pk < arg_compiled.length@@ -18476,10 +18492,10 @@
1847618492
end1847718493
pk = pk + 11847818494
end18479-
call_expr = "sp_" + cname + "_" + sanitize_name(mname) + "((sp_" + cname + " *)" + recv_tmp + ".v.p" + arm_arg_strs + ")"18495+
call_expr = "sp_" + @cls_names[owner_idx] + "_" + sanitize_name(mname) + "((sp_" + @cls_names[owner_idx] + " *)" + recv_tmp + ".v.p" + arm_arg_strs + ")"1848018496
rhs = call_expr1848118497
if is_poly_ret == 118482-
this_rt = cls_method_return(i, mname)18498+
this_rt = cls_method_return(owner_idx, mname)1848318499
rhs = box_val_to_poly(call_expr, this_rt)1848418500
end1848518501
# Narrowed `[]` arms (Approach 2): suppress user-class arms@@ -18487,7 +18503,7 @@
1848718503
# otherwise assign e.g. a string to the now-mrb_int result1848818504
# temp and fail the C compile. The runtime can't reach these1848918505
# arms anyway because the observation set narrowed past them.18490-
if narrowed_int_idx == 1 && cls_method_return(i, mname) != "int"18506+
if narrowed_int_idx == 1 && cls_method_return(owner_idx, mname) != "int"1849118507
# skip1849218508
else1849318509
emit(" if (" + recv_tmp + ".cls_id == " + cls_id_for_user_internal(i).to_s + ") " + tmp + " = " + rhs + ";")test/poly_dispatch_inherited_attr_reader.rbaddedView file
Loading diff…
test/poly_dispatch_inherited_attr_reader.rb.expectedaddedView file
Loading diff…
test/poly_dispatch_inherited_method.rbaddedView file
Loading diff…
test/poly_dispatch_inherited_method.rb.expectedaddedView file
Loading diff…
test/poly_dispatch_multilevel_inheritance.rbaddedView file
Loading diff…
test/poly_dispatch_multilevel_inheritance.rb.expectedaddedView file
Loading diff…