Commit 649bc00f
649bc00f5658Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 3 files · +1 added · ~2 modified
Description
Allow an always-raising method's result in value position
A method whose body unconditionally raises has a C void return type.
Using its (never-produced) result in value position -- v = boom,
sink(boom), or puts/print/p boom -- was rejected ('unsupported type
void'), even though the call diverges so the use is unreachable. This
blocked AOT-compiling a transpiled Rails app whose abstract base method is
raise NotImplementedError.
A void value in value position is nil-ish:
- infer_write_types / bind_call_params coerce a void RHS/argument to poly, so the local/param is declarable; codegen's emit_boxed already evaluates the (diverging) call and yields nil.
- puts/print/p gain a void arm alongside their existing nil arm, evaluating the argument for effect and rendering nil.
Adds test/void_value_in_value_position.rb.
Fixes #1397 Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]
Details
- Commit
- 649bc00f5658
- Parent
- b8ba5795b945
src/analyze_pass.cmodifiedView file
@@ -242,6 +242,10 @@
242242
else {243243
continue;244244
}245+
/* A void value assigned in value position (`v = always_raising_method`)246+
is nil-ish: type the slot poly so it is declarable. The RHS call is247+
emitted via emit_boxed, which evaluates it (it diverges) and yields nil. */248+
if (newt == TY_VOID) newt = TY_POLY;245249
if (!nm) continue;246250
LocalVar *lv = scope_local(comp_scope_of(c, id), nm);247251
if (!lv || lv->is_block_param) continue;@@ -1057,6 +1061,10 @@
10571061
}10581062
LocalVar *p = scope_local(m, m->pnames[k]);10591063
if (!p || p->rbs_seeded) continue;1064+
/* A void arg (`sink(always_raising_method)`) is nil-ish in value position:1065+
bind the param poly so it is declarable; the arg is emitted via1066+
emit_boxed (it diverges and yields nil). */1067+
if (at == TY_VOID) at = TY_POLY;10601068
/* A nil arg narrows against an object param (NULL encodes nil) but widens10611069
any non-object param to poly. Pass nil through to ty_unify only while10621070
the param is still unknown or already an object. */src/codegen_stmt.cmodifiedView file
Loading diff…
test/void_value_in_value_position.rbaddedView file
Loading diff…