Commit 542c20b4
542c20b4dce9Merged
Sam Ruby <[email protected]> · 5 months ago · 3 files · +2 added · ~1 modified
Description
codegen: add mutable_str arm to string-interpolation format dispatch (#1027)
compile_string_interp's arm-per-type dispatch covered every type tag
except mutable_str, so a #{...} slot whose expression returned
sp_String * (the mutable-string type backing String.new + <<)
fell through to the int-fallback arm at the end of the chain and
emitted %lld + (long long) cast. The slot rendered as a decimal
pointer address instead of the string's contents.
Direct << on the same value already worked — sp_String_append
accepts sp_String * directly. The type information was available;
only the interpolation format-spec dispatch missed the arm.
Fix mirrors the existing arms (bigint via sp_bigint_to_s, float via
sp_float_to_s, symbol via sp_sym_to_s, etc.) — emit %s and read
the chars via sp_String_cstr (already in lib/sp_runtime.h:1804).
Surfaces in roundhouse view emit after a lowerer pass coalesces
io << a; io << b; io << c runs in view bodies into a single
io << "...#{b}..."-style interpolation. The coalesced form
interpolates partial-render method calls that return sp_String *
(e.g. Views::Articles.form(article)), and those slots came out as
decimal addresses in the rendered HTML — visible in compare-spinel as
<form> elements replaced by stray text nodes, and in the toolchain
runner as assert_select("form") failing on a body containing
"31021302048" where the form should be. Other roundhouse targets
(typescript / crystal / rust / go / ruby) all interpolate cleanly
because their string primitives accept the mutable variant directly.
Adds test/i1027.rb: puts "[#{M.make}]" where M.make returns
String.new << "hello". Without the fix the test produces a decimal
pointer address; with the fix it produces [hello].
Details
- Commit
- 542c20b4dce9
- Parent
- 37a993fa0d85
spinel_codegen.rbmodifiedView file
elsif it == "sym_array_ptr_array" fmt = fmt + "%s" arg_exprs.push("sp_SymArrayPtrArray_inspect(" + compile_expr(inner) + ")") elsif it == "mutable_str" # `"#{s}"` on an sp_String * (the mutable variant # backing `String.new` + `<<`) reads the chars via # sp_String_cstr; without this arm the default int # fallback printed the pointer cast to long long. # Issue #1027. fmt = fmt + "%s" arg_exprs.push("sp_String_cstr(" + compile_expr(inner) + ")") else fmt = fmt + "%lld" arg_exprs.push("(long long)" + compile_expr(inner))test/i1027.rbaddedView file
Loading diff…
test/i1027.rb.expectedaddedView file
Loading diff…