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.last
1281512815 # Compile last as statement for side effects, then capture value
1281612816 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 call
1281812819 compile_stmt(last)
12819- last_val = compile_expr(last)
12820+ emit(" _fb->yielded_value = sp_box_nil();")
1282012821 else
12822+ if @nd_type[last] == "LocalVariableWriteNode" || @nd_type[last] == "LocalVariableOperatorWriteNode"
12823+ compile_stmt(last)
12824+ end
1282112825 last_val = compile_expr(last)
12826+ emit(" _fb->yielded_value = " + box_val_to_poly(last_val, last_type) + ";")
1282212827 end
12823- emit(" _fb->yielded_value = " + box_val_to_poly(last_val, last_type) + ";")
1282412828 end
1282512829 end
1282612830 pop_scope
@@ -17669,6 +17673,18 @@
1766917673 end
1767017674 return
1767117675 end
17676+ if t == "ParenthesesNode"
17677+ body = @nd_body[nid]
17678+ if body >= 0
17679+ pstmts = get_stmts(body)
17680+ pk = 0
17681+ while pk < pstmts.length
17682+ compile_stmt(pstmts[pk])
17683+ pk = pk + 1
17684+ end
17685+ end
17686+ return
17687+ end
1767217688 expr = compile_expr(nid)
1767317689 if expr != "0"
1767417690 emit(" " + expr + ";")