Commit 15a33057
15a3305780d0Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 1 file · ~1 modified
Description
Lower String += to a concat call for nullable-string operands too
local += rhs where the local is a string only lowered to sp_str_concat
when both the local and the rhs typed exactly "string"; a string?
(nullable-string -- e.g. a method returning nil-or-String, or
Digest::MD5.digest) operand fell through to a raw C vref += rhs, i.e.
const char * + const char * -- "invalid operands to binary +", a failed
cc. A const-char*-typed string is still a Ruby String regardless of
nullability.
Broaden the concat condition to base_type(...) == "string" on both sides
so string / string? combinations all lower to sp_str_concat (which
already treats a NULL/nil operand as empty). Verified with an equivalent
nil | String-returning method that produces the identical
const char * + const char * error the issue reports via aes-everywhere;
the fix lowers it to sp_str_concat and the result matches CRuby. Gate
green (test/bench/optcarrot 59662/self-host fixpoint).
Fixes #1341.
Co-Authored-By: Claude Opus 4.8 [email protected]
Details
- Commit
- 15a3305780d0
- Parent
- c7c2884b7f53
spinel_codegen.rbmodifiedView file
return end if op == "+" if vt == "string" && infer_type(@nd_expression[nid]) == "string" if base_type(vt) == "string" && base_type(infer_type(@nd_expression[nid])) == "string" # A `const char *`-typed string is still a Ruby String, including the # nullable `string?` slot a method like `mk -> nil | "x"` produces. # `vt OP= rhs` on two such operands must lower to a string concat, not # raw C pointer `+` (invalid operands to binary +). sp_str_concat # treats a NULL (nil) operand as empty. Issue #1341. emit(" " + vref + " = sp_str_concat(" + vref + ", " + val + ");") elsif vt == "complex" && infer_type(@nd_expression[nid]) == "complex" # `+=` on a struct doesn't compile in C; desugar to