Commit ce1d8a13
ce1d8a13c09dMerged
Yasuhiro Matsumoto <[email protected]> · 6 months ago · 1 file · ~1 modified
Description
fix(codegen): emit side effects for void last stmt in Fiber body
Co-authored-by: Claude [email protected]
Details
- Commit
- ce1d8a13c09d
- Parent
- f371958428d5
spinel_codegen.rbmodifiedView file
@@ -12814,13 +12814,17 @@
1281412814
last = stmts.last1281512815
# Compile last as statement for side effects, then capture value1281612816
last_type = infer_type(last)12817-
if @nd_type[last] == "LocalVariableWriteNode" || @nd_type[last] == "LocalVariableOperatorWriteNode"12817+
if last_type == "void"12818+
# Side-effect-only stmt (puts, print, etc.) — compile_expr would drop the call1281812819
compile_stmt(last)12819-
last_val = compile_expr(last)12820+
emit(" _fb->yielded_value = sp_box_nil();")1282012821
else12822+
if @nd_type[last] == "LocalVariableWriteNode" || @nd_type[last] == "LocalVariableOperatorWriteNode"12823+
compile_stmt(last)12824+
end1282112825
last_val = compile_expr(last)12826+
emit(" _fb->yielded_value = " + box_val_to_poly(last_val, last_type) + ";")1282212827
end12823-
emit(" _fb->yielded_value = " + box_val_to_poly(last_val, last_type) + ";")1282412828
end1282512829
end1282612830
pop_scope@@ -17669,6 +17673,18 @@
1766917673
end1767017674
return1767117675
end17676+
if t == "ParenthesesNode"17677+
body = @nd_body[nid]17678+
if body >= 017679+
pstmts = get_stmts(body)17680+
pk = 017681+
while pk < pstmts.length17682+
compile_stmt(pstmts[pk])17683+
pk = pk + 117684+
end17685+
end17686+
return17687+
end1767217688
expr = compile_expr(nid)1767317689
if expr != "0"1767417690
emit(" " + expr + ";")