Commit eedc1732
eedc17323ec3Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 2 files · +1 added · ~1 modified
Description
Treat a require reaching codegen as a runtime no-op
require / require_relative is resolved by textual splicing before
codegen, but the splicer only matches a require at column 0 (start of line
or right after a newline). An indented require -- inside an if branch, a
module, or a method body -- survived into codegen as an unsupported CallNode
and hard-failed the compile, while a top-level require warns and continues.
emit_call now lowers a receiverless require/require_relative to a no-op (yielding nil in value position). Spinel inlines real dependencies at compile time and provides stdlib natively, so a require evaluated at runtime has nothing to do.
Fixes #1400 Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]
Details
- Commit
- eedc17323ec3
- Parent
- 289ce84baf6f
src/codegen_call.cmodifiedView file
void emit_call(Compiler *c, int id, Buf *b) { const NodeTable *nt = c->nt; /* `require` / `require_relative` is a compile-time directive: top-level ones are textually spliced away before codegen, and native libs are provided by the runtime. One that still reaches codegen -- indented inside an `if`, module, or method body -- is a runtime no-op (it would otherwise be an unsupported CallNode). Returns nil in value position via emit_boxed. */ { int rcv = nt_ref(nt, id, "receiver"); const char *cn = nt_str(nt, id, "name"); if (rcv < 0 && cn && (!strcmp(cn, "require") || !strcmp(cn, "require_relative"))) { buf_puts(b, "0"); return; } } if (emit_partition_expr(c, id, b)) return; if (emit_collect_expr(c, id, b)) return; if (emit_predicate_expr(c, id, b)) return;test/require_in_conditional.rbaddedView file
Loading diff…