Commit f0185545
f0185545fa6fMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 1 file · ~1 modified
Description
Kernel#warn writes its arguments to stderr
warn previously fell through to the unresolved-call warning and dropped the output. Emit each argument to stderr with a trailing newline, converting non-string scalars via their to_s helper.
Co-Authored-By: Claude Opus 4.8 [email protected]
Details
- Commit
- f0185545fa6f
- Parent
- ae7176e32942
src/codegen.cmodifiedView file
@@ -4932,6 +4932,20 @@
49324932
}49334933
if (!strcmp(name, "print")) { for (int k = 0; k < argc; k++) emit_print_one(c, argv[k], b, indent); return 1; }49344934
if (!strcmp(name, "p")) { for (int k = 0; k < argc; k++) emit_p_one(c, argv[k], b, indent); return 1; }4935+
if (!strcmp(name, "warn")) {4936+
/* Kernel#warn: each argument to stderr with a trailing newline */4937+
for (int k = 0; k < argc; k++) {4938+
TyKind at = comp_ntype(c, argv[k]);4939+
emit_indent(b, indent); buf_puts(b, "fputs(");4940+
if (at == TY_STRING) emit_expr(c, argv[k], b);4941+
else if (at == TY_INT) { buf_puts(b, "sp_int_to_s("); emit_expr(c, argv[k], b); buf_puts(b, ")"); }4942+
else if (at == TY_FLOAT) { buf_puts(b, "sp_float_to_s("); emit_expr(c, argv[k], b); buf_puts(b, ")"); }4943+
else if (at == TY_SYMBOL) { buf_puts(b, "sp_sym_to_s("); emit_expr(c, argv[k], b); buf_puts(b, ")"); }4944+
else { buf_puts(b, "((void)("); emit_expr(c, argv[k], b); buf_puts(b, "), \"\")"); }4945+
buf_puts(b, ", stderr); fputc('\\n', stderr);\n");4946+
}4947+
return 1;4948+
}49354949
return 0;49364950
}49374951