Commit 00b1763d
00b1763d3270Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 3 files · +2 added · ~1 modified
Description
fix(codegen): Kernel#warn + at_exit stubs (#734)
warn "msg" and at_exit { ... } used to fall through to the
unresolved-call warning ("cannot resolve call to 'warn' on (no
receiver) (emitting 0)"), making any program that uses either
emit noisy compile-time warnings.
Fix:
- warn: route through compile_stderr_puts (the existing helper
that already powers
$stderr.puts). Each arg is fprintf'd to stderr with a trailing newline -- matches Kernel#warn semantics for the typical 0..N arg case spinel users hit. - at_exit: emit nothing. spinel is AOT and doesn't model atexit hooks; the block can't be deferred and registering it would require new runtime plumbing. Stubbing prevents the unresolved-call noise and the silent block-body type errors that would otherwise surface.
Both names get added to the puts/print/printf statement dispatch
list so call-as-expression positions (x = warn("...")) take the
statement path and return "0" as the C expression.
Test: test/warn_kernel.rb verifies the call sites compile, warn runs without crashing, and post-warn puts is reached. (warn's stderr output isn't asserted since the runner only captures stdout.)
469 tests pass; optcarrot checksum 59662.
Closes #734
Co-Authored-By: Claude Opus 4.7 [email protected]
Details
- Commit
- 00b1763d3270
- Parent
- 6fe12da7e47d
spinel_codegen.rbmodifiedView file
# side-effect through the statement handler and pass "0" (nil in C) # up as the expression value. Without this, the call falls through # to warn_unresolved_call and the IO is silently dropped. if mname == "puts" || mname == "print" || mname == "printf" if mname == "puts" || mname == "print" || mname == "printf" || mname == "warn" || mname == "at_exit" if compile_io_call_stmt(nid, mname, -1) == 1 return "0" end return 1 end end # `warn arg, arg, ...` -- write each arg to stderr followed by a # newline (matching Kernel#warn). Issue #734. if mname == "warn" if recv < 0 compile_stderr_puts(nid) return 1 end end # `at_exit { ... }` -- spinel doesn't model atexit hooks; emit # nothing and let the block be ignored. A real implementation # would push the block onto a static registry called from main's # exit path; not worth the runtime plumbing for a generally- # uncommon pattern. Issue #734. if mname == "at_exit" if recv < 0 return 1 end end 0 endtest/warn_kernel.rbaddedView file
Loading diff…
test/warn_kernel.rb.expectedaddedView file
Loading diff…