Commit 6f0c5e19
6f0c5e1985e2Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 1 file · ~1 modified
Description
File.write: stringify a poly data argument
A poly-typed data argument (e.g. the result of a poly-receiver dispatch whose candidates return different types) is converted via sp_poly_to_s instead of being assigned raw to the const char* slot.
Fixes bundle_classd_27.
Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]
Details
- Commit
- 6f0c5e1985e2
- Parent
- 2d3b6b81ebed
src/codegen.cmodifiedView file
@@ -6108,7 +6108,11 @@
61086108
if ((!strcmp(name, "write") || !strcmp(name, "binwrite")) && argc == 2) {61096109
/* runtime write is void; Ruby returns the byte count */61106110
buf_puts(b, "({ const char *_wp = "); emit_expr(c, argv[0], b);6111-
buf_puts(b, "; const char *_wd = "); emit_expr(c, argv[1], b);6111+
buf_puts(b, "; const char *_wd = ");6112+
if (comp_ntype(c, argv[1]) == TY_POLY) {6113+
buf_puts(b, "sp_poly_to_s("); emit_expr(c, argv[1], b); buf_puts(b, ")");6114+
}6115+
else emit_expr(c, argv[1], b);61126116
buf_puts(b, "; sp_file_write(_wp, _wd); (mrb_int)sp_str_byte_len(_wd); })"); return;61136117
}61146118
if ((!strcmp(name, "exist?") || !strcmp(name, "exists?") || !strcmp(name, "readable?")) && argc == 1) {