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