Commit b9e53f28

b9e53f28bcfcMerged

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

Description

fix(codegen): mutable_str -> string return coerce at function exit

Function bodies that build an sp_String * via io = ""; io << "..."; io; returned the raw sp_String * even when the function's declared return type was const char *. clang errored -Wincompatible-pointer-types on the bare return.

Add an arm in compile_body_return_inner's implicit-return path: when expr_type == "mutable_str" and the declared return is string, emit return (val)->data; so the buffer pointer flows out.

Clears the 3 sp_Views_Articles_cls_*_json return warnings in #685's roundhouse emit.

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

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

Details

Commit
b9e53f28bcfc
Parent
ba7b1dfb5efc

spinel_codegen.rbmodifiedView file

@@ -40030,6 +40030,12 @@
4003040030 # const-char-*-typed return signature matches.
4003140031 @needs_rb_value = 1
4003240032 emit(" return (" + val + ").v.s;")
40033+ elsif expr_type == "mutable_str" && base_type(return_type) == "string"
40034+ # Body builds an sp_String * via `<<` chain (the `io = ""; io
40035+ # << "..."; io;` idiom) but the function's declared return
40036+ # type is `const char *`. Read the underlying buffer via
40037+ # `->data` so the return value matches the sig.
40038+ emit(" return (" + val + ")->data;")
4003340039 elsif (expr_type == "int" || expr_type == "nil") && is_nullable_pointer_type(return_type) == 1 && fetch_with_nil_default?(last) == 1
4003440040 # Issue #671: `hash.fetch(k, nil)` against an int-leaf hash
4003540041 # (typically empty `@slots = {}`) returns int but the