Commit b7853557
b78535570c7dMerged
Yusuke Endoh <[email protected]> · 6 months ago · 2 files · +1 added · ~1 modified
Description
fix(codegen): forward params for bare super in initializer
Bare super (no args, no parens) parses as
ForwardingSuperNode, distinct from super(args) which parses
as SuperNode. emit_constructor only handled SuperNode,
so the call to the parent's initialize was silently dropped.
Treat both node types as super calls. For ForwardingSuperNode,
forward the current init's params 1:1 to the parent.
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- b78535570c7d
- Parent
- c64c82b343ed
spinel_codegen.rbmodifiedView file
@@ -12004,21 +12004,38 @@
1200412004
declare_method_locals(bid, pnames)1200512005
stmts = get_stmts(bid)1200612006
stmts.each { |sid|12007-
if @nd_type[sid] == "SuperNode"12007+
# Bare `super` parses as ForwardingSuperNode; `super(args)`12008+
# parses as SuperNode. Both need to call the parent's12009+
# initialize. For ForwardingSuperNode we forward the12010+
# current method's params.12011+
is_super = (@nd_type[sid] == "SuperNode" || @nd_type[sid] == "ForwardingSuperNode")12012+
if is_super1200812013
if @cls_parents[ci] != ""1200912014
pi = find_class_idx(@cls_parents[ci])1201012015
if pi >= 01201112016
super_args = ""12012-
args_id = @nd_arguments[sid]12013-
if args_id >= 012014-
arg_ids = get_args(args_id)12015-
ak = 012016-
while ak < arg_ids.length12017-
if ak > 012017+
if @nd_type[sid] == "ForwardingSuperNode"12018+
# Forward the current init's params 1:1.12019+
fk = 012020+
while fk < pnames.length12021+
if fk > 01201812022
super_args = super_args + ", "1201912023
end12020-
super_args = super_args + compile_expr(arg_ids[ak])12021-
ak = ak + 112024+
super_args = super_args + "lv_" + pnames[fk]12025+
fk = fk + 112026+
end12027+
else12028+
args_id = @nd_arguments[sid]12029+
if args_id >= 012030+
arg_ids = get_args(args_id)12031+
ak = 012032+
while ak < arg_ids.length12033+
if ak > 012034+
super_args = super_args + ", "12035+
end12036+
super_args = super_args + compile_expr(arg_ids[ak])12037+
ak = ak + 112038+
end1202212039
end1202312040
end1202412041
emit_raw(" sp_" + @cls_parents[ci] + "_initialize((sp_" + @cls_parents[ci] + " *)self" + (super_args != "" ? ", " + super_args : "") + ");")@@ -12069,7 +12086,7 @@
1206912086
emit_raw(" " + self_arrow + ivar + " = " + val + ";")1207012087
end1207112088
else12072-
if @nd_type[sid] != "SuperNode"12089+
if is_super == false1207312090
# Compile other statements (e.g., method calls like @arr[0] = val)1207412091
compile_stmt(sid)1207512092
endtest/super_forwarding.rbaddedView file
Loading diff…