Commit 483fd088

483fd088b459Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 3 files · +2 added · ~1 modified

Description

fix(codegen): File.write at expression level mirrors File.binwrite

The statement-context lowering at compile_control_call_stmt already routed File.write to sp_file_write. The expression- level path at compile_expr only recognized File.binwrite; File.write as the tail expression of a method body fell through to compile_expr (the route compile_body_return_inner takes for arbitrary CallNodes outside the small hardcoded side-effect list) and emitted the unresolved-call warning plus a literal 0, silently dropping the write.

Alias write to binwrite in the same arm so both call shapes lower identically. File.write in CRuby returns the byte count written; we return 0 to match the statement-context lowering (which also discards the count). The unresolved-call warning on Ori Pekelman's #549 repro disappears with this change.

Refs #549

Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]

Details

Commit
483fd088b459
Parent
d5413c7f577d

spinel_codegen.rbmodifiedView file

@@ -17802,11 +17802,15 @@
1780217802 if mname == "delete"
1780317803 return "(sp_file_delete(" + compile_arg0(nid) + "), 0)"
1780417804 end
17805- if mname == "binwrite"
17805+ if mname == "binwrite" || mname == "write"
1780617806 # NOTE: `sp_file_write` uses fputs, so an embedded NUL
17807- # in the payload truncates the write — fine for the
17807+ # in the payload truncates the write; fine for the
1780817808 # optcarrot save-RAM dead-code path that surfaced
17809- # this, not safe for general binary use.
17809+ # this, not safe for general binary use. File.write
17810+ # in CRuby returns the number of bytes written; we
17811+ # return 0 to match the statement-context lowering at
17812+ # compile_control_call_stmt (which also discards the
17813+ # byte count).
1781017814 args_id_bw = @nd_arguments[nid]
1781117815 if args_id_bw >= 0
1781217816 a_bw = get_args(args_id_bw)