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

@@ -16115,7 +16115,7 @@
1611516115 # side-effect through the statement handler and pass "0" (nil in C)
1611616116 # up as the expression value. Without this, the call falls through
1611716117 # to warn_unresolved_call and the IO is silently dropped.
16118- if mname == "puts" || mname == "print" || mname == "printf"
16118+ if mname == "puts" || mname == "print" || mname == "printf" || mname == "warn" || mname == "at_exit"
1611916119 if compile_io_call_stmt(nid, mname, -1) == 1
1612016120 return "0"
1612116121 end
@@ -31186,6 +31186,24 @@
3118631186 return 1
3118731187 end
3118831188 end
31189+ # `warn arg, arg, ...` -- write each arg to stderr followed by a
31190+ # newline (matching Kernel#warn). Issue #734.
31191+ if mname == "warn"
31192+ if recv < 0
31193+ compile_stderr_puts(nid)
31194+ return 1
31195+ end
31196+ end
31197+ # `at_exit { ... }` -- spinel doesn't model atexit hooks; emit
31198+ # nothing and let the block be ignored. A real implementation
31199+ # would push the block onto a static registry called from main's
31200+ # exit path; not worth the runtime plumbing for a generally-
31201+ # uncommon pattern. Issue #734.
31202+ if mname == "at_exit"
31203+ if recv < 0
31204+ return 1
31205+ end
31206+ end
3118931207 0
3119031208 end
3119131209