Commit 4510cc9c
4510cc9c4f62Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 3 files · +2 added · ~1 modified
Description
Merge pull request #233 from mame/pr/super-arg-cast
fix(codegen): cast super-call args to parent's declared param types
Details
- Commit
- 4510cc9c4f62
- Parent
- ff464f13ad05
- Merge parent
- 75d32b64f405
spinel_codegen.rbmodifiedView file
@@ -13987,6 +13987,23 @@
1398713987
if @cls_parents[ci] != ""1398813988
pi = find_class_idx(@cls_parents[ci])1398913989
if pi >= 013990+
# Look up the parent's init signature so we can cast13991+
# each forwarded arg to the parent's declared type13992+
# when it differs (parent's param-type inference may13993+
# not see this child's type narrowing).13994+
p_pnames = "".split(",")13995+
p_ptypes = "".split(",")13996+
p_init_idx = cls_find_method_direct(pi, "initialize")13997+
if p_init_idx >= 013998+
p_all_params = @cls_meth_params[pi].split("|")13999+
p_all_ptypes = @cls_meth_ptypes[pi].split("|")14000+
if p_init_idx < p_all_params.length14001+
p_pnames = p_all_params[p_init_idx].split(",")14002+
end14003+
if p_init_idx < p_all_ptypes.length14004+
p_ptypes = p_all_ptypes[p_init_idx].split(",")14005+
end14006+
end1399014007
super_args = ""1399114008
if @nd_type[sid] == "ForwardingSuperNode"1399214009
# Forward the current init's params 1:1.@@ -13995,7 +14012,13 @@
1399514012
if fk > 01399614013
super_args = super_args + ", "1399714014
end13998-
super_args = super_args + "lv_" + pnames[fk]14015+
arg_expr = "lv_" + pnames[fk]14016+
if fk < p_ptypes.length && fk < ptypes.length14017+
if p_ptypes[fk] != ptypes[fk] && p_ptypes[fk] != ""14018+
arg_expr = "(" + c_type(p_ptypes[fk]) + ")" + arg_expr14019+
end14020+
end14021+
super_args = super_args + arg_expr1399914022
fk = fk + 11400014023
end1400114024
else@@ -14007,7 +14030,14 @@
1400714030
if ak > 01400814031
super_args = super_args + ", "1400914032
end14010-
super_args = super_args + compile_expr(arg_ids[ak])14033+
arg_expr2 = compile_expr(arg_ids[ak])14034+
if ak < p_ptypes.length14035+
at_arg = infer_type(arg_ids[ak])14036+
if p_ptypes[ak] != at_arg && p_ptypes[ak] != ""14037+
arg_expr2 = "(" + c_type(p_ptypes[ak]) + ")" + arg_expr214038+
end14039+
end14040+
super_args = super_args + arg_expr21401114041
ak = ak + 11401214042
end1401314043
endtest/super_arg_cross_class_cast.rbaddedView file
Loading diff…
test/super_arg_cross_class_cast.rb.expectedaddedView file
Loading diff…