Commit 66e7a44e

66e7a44e4dc8Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 1 file · ~1 modified

Description

fix(codegen): mutable_str -> string coerce at call boundary

Functions whose body builds a mutable string (io = ""; io << "..."; io;) had their return type inferred as mutable_str, but downstream callers with const char * params got the raw sp_String * pointer and clang errored with -Wincompatible-pointer-types.

compile_expr_for_expected_type's expected_base == "string" arm handled int/bigint/float/bool/nil/symbol -> string coerces but omitted the mutable_str case. Add the arm: emit (val)->data to extract the underlying buffer.

Clears 6 of the 18 remaining warnings in #685's roundhouse emit (every sp_ActionController_Base_render() callsite passing an sp_Views_Articles_cls_() result).

Tests: default 460/0/0, promote 460/0/0, optcarrot checksum 59662.

Co-Authored-By: Claude Opus 4.7 [email protected]

Details

Commit
66e7a44e4dc8
Parent
55de40337b6a

spinel_codegen.rbmodifiedView file

@@ -6293,6 +6293,15 @@
62936293 if at == "symbol"
62946294 return "sp_sym_to_s(" + val + ")"
62956295 end
6296+ # sp_String * (the mutable_str builder type) -> const char *: read
6297+ # the underlying buffer via `->data`. Surfaces whenever a function
6298+ # whose body builds a mutable string (`io = ""; io << "..."; io;`)
6299+ # gets passed to a callee with a const char * param. The function's
6300+ # return type was inferred too narrowly upstream, but the call site
6301+ # can recover at the boundary.
6302+ if at == "mutable_str"
6303+ return "(" + val + ")->data"
6304+ end
62966305 end
62976306 if is_obj_type(expected_base) == 1 && at == "poly"
62986307 cname = expected_base[4, expected_base.length - 4]