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's
12009+ # initialize. For ForwardingSuperNode we forward the
12010+ # current method's params.
12011+ is_super = (@nd_type[sid] == "SuperNode" || @nd_type[sid] == "ForwardingSuperNode")
12012+ if is_super
1200812013 if @cls_parents[ci] != ""
1200912014 pi = find_class_idx(@cls_parents[ci])
1201012015 if pi >= 0
1201112016 super_args = ""
12012- args_id = @nd_arguments[sid]
12013- if args_id >= 0
12014- arg_ids = get_args(args_id)
12015- ak = 0
12016- while ak < arg_ids.length
12017- if ak > 0
12017+ if @nd_type[sid] == "ForwardingSuperNode"
12018+ # Forward the current init's params 1:1.
12019+ fk = 0
12020+ while fk < pnames.length
12021+ if fk > 0
1201812022 super_args = super_args + ", "
1201912023 end
12020- super_args = super_args + compile_expr(arg_ids[ak])
12021- ak = ak + 1
12024+ super_args = super_args + "lv_" + pnames[fk]
12025+ fk = fk + 1
12026+ end
12027+ else
12028+ args_id = @nd_arguments[sid]
12029+ if args_id >= 0
12030+ arg_ids = get_args(args_id)
12031+ ak = 0
12032+ while ak < arg_ids.length
12033+ if ak > 0
12034+ super_args = super_args + ", "
12035+ end
12036+ super_args = super_args + compile_expr(arg_ids[ak])
12037+ ak = ak + 1
12038+ end
1202212039 end
1202312040 end
1202412041 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 end
1207112088 else
12072- if @nd_type[sid] != "SuperNode"
12089+ if is_super == false
1207312090 # Compile other statements (e.g., method calls like @arr[0] = val)
1207412091 compile_stmt(sid)
1207512092 end