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

@@ -15138,6 +15138,14 @@
1513815138 elsif it == "sym_array_ptr_array"
1513915139 fmt = fmt + "%s"
1514015140 arg_exprs.push("sp_SymArrayPtrArray_inspect(" + compile_expr(inner) + ")")
15141+ elsif it == "mutable_str"
15142+ # `"#{s}"` on an sp_String * (the mutable variant
15143+ # backing `String.new` + `<<`) reads the chars via
15144+ # sp_String_cstr; without this arm the default int
15145+ # fallback printed the pointer cast to long long.
15146+ # Issue #1027.
15147+ fmt = fmt + "%s"
15148+ arg_exprs.push("sp_String_cstr(" + compile_expr(inner) + ")")
1514115149 else
1514215150 fmt = fmt + "%lld"
1514315151 arg_exprs.push("(long long)" + compile_expr(inner))