Commit e7167568
e71675689df9Merged
Ryan Seys <[email protected]> · 6 months ago · 2 files · +1 added · ~1 modified
Description
fix(codegen): walk @nd_parts in scan_new_calls
A method called only inside string interpolation never widens its
parameter types: def cap(s); s + "_cap"; end; puts "lv_#{cap(name)}"
declares cap's s as the default mrb_int and the call site passes
a const char *, yielding a C int-conversion error. The cause is that
scan_new_calls' AST recursion enumerates @nd_body / @nd_stmts /
@nd_receiver / @nd_arguments / @nd_args / @nd_expression / @nd_predicate
/ @nd_subsequent / @nd_else_clause / @nd_left / @nd_right / @nd_block /
@nd_elements / @nd_conditions but not @nd_parts, so the
EmbeddedStatementsNode body inside an InterpolatedStringNode is never
visited and the call inside #{...} is invisible to the param-widener.
Fix is one extra recursion arm at the tail of scan_new_calls: parse @nd_parts and recurse into each component. EmbeddedStatementsNode already carries its body via @nd_stmts, so once the parts walk reaches the embedded node the existing @nd_stmts arm picks up the inner call and routes it through the same param-type unification path that other call sites use. scan_features_children was already correct here — its push_child_ids helper enumerates @nd_parts — so the bug was localized to scan_new_calls.
Test exercises four shapes inside puts "...#{...}...":
- one-arg method whose param widens to string
- two-arg method whose two params both widen to string
- one-arg method whose param widens to int (regression-guard for the
case where widening should preserve
intagainst a literal int arg) - one-arg method whose param widens to bool
CRuby and Spinel both produce the same four output lines.
Bootstrap: gen2.c == gen3.c. Tests: 202 pass.
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- e71675689df9
- Parent
- 02005f26deba
spinel_codegen.rbmodifiedView file
scan_new_calls(conds[k]) k = k + 1 end # InterpolatedStringNode and friends carry their components in @nd_parts. # Without this, an EmbeddedStatementsNode inside `"#{...}"` is the only # call site for a method whose param type would otherwise widen, and # the param keeps its default `int` => C error at the call site. parts = parse_id_list(@nd_parts[nid]) k = 0 while k < parts.length scan_new_calls(parts[k]) k = k + 1 end end def update_ivar_types_from_paramstest/interp_method_widening.rbaddedView file
Loading diff…