Commit 93ded8ff
93ded8ff43d7Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 1 file · ~1 modified
Description
Type str % poly_args as String, not poly
The poly-operand arithmetic rule returned TY_POLY for any %/+/* with a poly operand, catching (printf formatting on a string with a poly argument) before the string-% rule could type it as String. The node then boxed as already-poly and the const char* format result was assigned straight into an sp_RbVal slot. Exclude rt==String % from the poly-arith rule so it falls through to the formatting path.
Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]
Details
- Commit
- 93ded8ff43d7
- Parent
- 238b097627fd
src/analyze_infer.cmodifiedView file
@@ -1325,8 +1325,11 @@
13251325
13261326
/* poly receiver / poly operand: result type of operations on sp_RbVal */13271327
if (recv >= 0 && (rt == TY_POLY || a0 == TY_POLY)) {1328-
if (!strcmp(name, "+") || !strcmp(name, "-") || !strcmp(name, "*") ||1329-
!strcmp(name, "/") || !strcmp(name, "%") || !strcmp(name, "**"))1328+
/* `str % poly_args` is printf-style formatting (result string), not a poly1329+
arithmetic modulo -- defer to the rt==TY_STRING path below. */1330+
if (!(rt == TY_STRING && !strcmp(name, "%")) &&1331+
(!strcmp(name, "+") || !strcmp(name, "-") || !strcmp(name, "*") ||1332+
!strcmp(name, "/") || !strcmp(name, "%") || !strcmp(name, "**")))13301333
return TY_POLY;13311334
if (!strcmp(name, "<") || !strcmp(name, ">") || !strcmp(name, "<=") ||13321335
!strcmp(name, ">=") || !strcmp(name, "==") || !strcmp(name, "!=") ||