Commit 91917fd2
91917fd23f4cMerged
Ori Pekelman <[email protected]> · 6 months ago · 3 files · +2 added · ~1 modified
Description
fix(codegen): keep call's side effect when boxing nil-typed return
box_value_to_poly for at == "nil" returned the bare literal
"sp_box_nil()", discarding the val argument. The poly dispatch
loop calls this with val = "sp_<Subclass>_method(...)" — the
actual method call. Discarding it means: when a subclass override's
static return type is nil (e.g. its body is puts ... or
hash[k] = v whose return is nil-typed), the cls_id arm emits a
bare sp_box_nil() and the override never executes.
Equivalent for any base class with an empty body: empty body's inferred return is also nil, so even the base call is dropped.
Emit the val for its side effect, then yield nil:
return "((void)(" + val + "), sp_box_nil())"
The (void) cast suppresses the (benign) "expression result unused"
warning when val is e.g. a function returning int.
Repro lives in test/poly_nil_return_dispatch.rb. Surfaced building the tep Sinatra-clone — Tep::Filter#before's empty base body made every user-supplied filter silently no-op until we added a placeholder return.
Co-Authored-By: Claude Opus 4.7 [email protected]
Details
- Commit
- 91917fd23f4c
- Parent
- 8964075ee5d1
spinel_codegen.rbmodifiedView file
return "sp_box_bool(" + val + ")" end if at == "nil" return "sp_box_nil()" # `val` may be a side-effecting call (e.g. an arm in a # cls_id-dispatched table where the user-defined override # returns nil because its body is a `puts` / similar). Drop # the value but keep the side effect via the comma operator; # otherwise the generated dispatch silently elides the call # for any subclass whose method's static return type is nil. return "((void)(" + val + "), sp_box_nil())" end if at == "symbol" return "sp_box_sym(" + val + ")"test/poly_nil_return_dispatch.rbaddedView file
Loading diff…
test/poly_nil_return_dispatch.rb.expectedaddedView file
Loading diff…