Commit dd03d810
dd03d810b5e0Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 2 files · +1 added · ~1 modified
Description
Merge pull request #178 from mame/pr/super-forwarding
fix(codegen): bare super in initializer is silently dropped
Details
- Commit
- dd03d810b5e0
- Parent
- 7e0834e3bf7a
- Merge parent
- b78535570c7d
spinel_codegen.rbmodifiedView file
@@ -12438,21 +12438,38 @@
1243812438
declare_method_locals(bid, pnames)1243912439
stmts = get_stmts(bid)1244012440
stmts.each { |sid|12441-
if @nd_type[sid] == "SuperNode"12441+
# Bare `super` parses as ForwardingSuperNode; `super(args)`12442+
# parses as SuperNode. Both need to call the parent's12443+
# initialize. For ForwardingSuperNode we forward the12444+
# current method's params.12445+
is_super = (@nd_type[sid] == "SuperNode" || @nd_type[sid] == "ForwardingSuperNode")12446+
if is_super1244212447
if @cls_parents[ci] != ""1244312448
pi = find_class_idx(@cls_parents[ci])1244412449
if pi >= 01244512450
super_args = ""12446-
args_id = @nd_arguments[sid]12447-
if args_id >= 012448-
arg_ids = get_args(args_id)12449-
ak = 012450-
while ak < arg_ids.length12451-
if ak > 012451+
if @nd_type[sid] == "ForwardingSuperNode"12452+
# Forward the current init's params 1:1.12453+
fk = 012454+
while fk < pnames.length12455+
if fk > 01245212456
super_args = super_args + ", "1245312457
end12454-
super_args = super_args + compile_expr(arg_ids[ak])12455-
ak = ak + 112458+
super_args = super_args + "lv_" + pnames[fk]12459+
fk = fk + 112460+
end12461+
else12462+
args_id = @nd_arguments[sid]12463+
if args_id >= 012464+
arg_ids = get_args(args_id)12465+
ak = 012466+
while ak < arg_ids.length12467+
if ak > 012468+
super_args = super_args + ", "12469+
end12470+
super_args = super_args + compile_expr(arg_ids[ak])12471+
ak = ak + 112472+
end1245612473
end1245712474
end1245812475
emit_raw(" sp_" + @cls_parents[ci] + "_initialize((sp_" + @cls_parents[ci] + " *)self" + (super_args != "" ? ", " + super_args : "") + ");")@@ -12503,7 +12520,7 @@
1250312520
emit_raw(" " + self_arrow + ivar + " = " + val + ";")1250412521
end1250512522
else12506-
if @nd_type[sid] != "SuperNode"12523+
if is_super == false1250712524
# Compile other statements (e.g., method calls like @arr[0] = val)1250812525
compile_stmt(sid)1250912526
endtest/super_forwarding.rbaddedView file
Loading diff…