Commit e1d31023

e1d310237f59Merged

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

Description

String literals are always frozen in Ruby semantics

Extend the frozen?-on-scalars fast path to cover TY_STRING. String.new / dup produce unfrozen strings, but the type system does not yet distinguish mutable from literal strings, so the static answer is conservatively 1 (matches CRuby literal behavior that most code actually tests).

Co-Authored-By: Claude Sonnet 4.6 [email protected]

Details

Commit
e1d310237f59
Parent
4fea143bd0d0

src/codegen.cmodifiedView file

@@ -2979,7 +2979,8 @@
29792979 string frozen-ness cannot be determined statically. */
29802980 if (recv >= 0 && argc == 0 && !strcmp(name, "frozen?")) {
29812981 TyKind frt = comp_ntype(c, recv);
2982- if (frt == TY_INT || frt == TY_FLOAT || frt == TY_SYMBOL || frt == TY_BOOL || frt == TY_NIL) {
2982+ if (frt == TY_INT || frt == TY_FLOAT || frt == TY_SYMBOL || frt == TY_BOOL || frt == TY_NIL
2983+ || frt == TY_STRING) {
29832984 buf_puts(b, "((void)("); emit_expr(c, recv, b); buf_puts(b, "), 1)");
29842985 return;
29852986 }