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 end
1786517865 j = j + 1
1786617866 end
17867+ if @cls_parents[ci] != ""
17868+ pi = find_class_idx(@cls_parents[ci])
17869+ if pi >= 0
17870+ return cls_has_attr_reader(pi, mname)
17871+ end
17872+ end
1786717873 0
1786817874 end
1786917875
@@ -18116,7 +18122,7 @@
1811618122 ci_s = 0
1811718123 diverges = 0
1811818124 while ci_s < @cls_names.length
18119- if cls_find_method_direct(ci_s, mname) >= 0
18125+ if cls_find_method(ci_s, mname) >= 0
1812018126 urt = cls_method_return(ci_s, mname)
1812118127 if urt != "" && urt != "string"
1812218128 diverges = 1
@@ -18144,7 +18150,7 @@
1814418150 ci = 0
1814518151 while ci < @cls_names.length
1814618152 rt = ""
18147- if cls_find_method_direct(ci, mname) >= 0
18153+ if cls_find_method(ci, mname) >= 0
1814818154 rt = cls_method_return(ci, mname)
1814918155 elsif cls_has_attr_reader(ci, mname) == 1
1815018156 # An attr_reader returns the ivar type. .
@@ -18417,6 +18423,16 @@
1841718423 while i < @cls_names.length
1841818424 cname = @cls_names[i]
1841918425 midx = cls_find_method_direct(i, mname)
18426+ owner_idx = i
18427+ if midx < 0
18428+ owner_name = find_method_owner(i, mname)
18429+ if owner_name != ""
18430+ owner_idx = find_class_idx(owner_name)
18431+ if owner_idx >= 0
18432+ midx = cls_find_method_direct(owner_idx, mname)
18433+ end
18434+ end
18435+ end
1842018436 if midx >= 0
1842118437 # 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 share
1842518441 # 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 = 0
1842918445 while pk < arm_ptypes.length
1843018446 if pk < arg_compiled.length
@@ -18476,10 +18492,10 @@
1847618492 end
1847718493 pk = pk + 1
1847818494 end
18479- 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_expr
1848118497 if is_poly_ret == 1
18482- 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 end
1848518501 # Narrowed `[]` arms (Approach 2): suppress user-class arms
@@ -18487,7 +18503,7 @@
1848718503 # otherwise assign e.g. a string to the now-mrb_int result
1848818504 # temp and fail the C compile. The runtime can't reach these
1848918505 # 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 # skip
1849218508 else
1849318509 emit(" if (" + recv_tmp + ".cls_id == " + cls_id_for_user_internal(i).to_s + ") " + tmp + " = " + rhs + ";")