summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Patterson <tenderlove@ruby-lang.org>2025-07-21 08:20:45 -0700
committergit <svn-admin@ruby-lang.org>2025-07-21 23:04:42 +0000
commita495e6a44ce8cff17461b250e32ab63e409a642d (patch)
tree4c882b5a562dc63c0da5726f10d1008ae355d516
parent21c78cb0f72f81052323292a1b9fc7a20dee44f6 (diff)
[ruby/prism] Clear flags on interpolated strings
When inner strings aren't frozen, we need to clear the flags on interpolated string nodes so that we don't emit wrong instructions. The compiler is currently incorrectly emitting frozen strings because the parser is erroneously declaring interpolated strings as "frozen". We need to fix this behavior in the parser so we can fix the compiler in CRuby. This patch is a partial fix for [this bug](https://bugs.ruby-lang.org/issues/21187) https://github.com/ruby/prism/commit/eda693f056
-rw-r--r--prism/prism.c4
-rw-r--r--test/prism/result/static_literals_test.rb5
2 files changed, 9 insertions, 0 deletions
diff --git a/prism/prism.c b/prism/prism.c
index 85647020d8..a40e0ebeb0 100644
--- a/prism/prism.c
+++ b/prism/prism.c
@@ -5279,6 +5279,10 @@ pm_interpolated_string_node_append(pm_interpolated_string_node_t *node, pm_node_
switch (PM_NODE_TYPE(part)) {
case PM_STRING_NODE:
+ // If inner string is not frozen, clear flags for this string
+ if (!PM_NODE_FLAG_P(part, PM_STRING_FLAGS_FROZEN)) {
+ CLEAR_FLAGS(node);
+ }
part->flags = (pm_node_flags_t) ((part->flags | PM_NODE_FLAG_STATIC_LITERAL | PM_STRING_FLAGS_FROZEN) & ~PM_STRING_FLAGS_MUTABLE);
break;
case PM_INTERPOLATED_STRING_NODE:
diff --git a/test/prism/result/static_literals_test.rb b/test/prism/result/static_literals_test.rb
index dcfc692897..cc07027916 100644
--- a/test/prism/result/static_literals_test.rb
+++ b/test/prism/result/static_literals_test.rb
@@ -4,6 +4,11 @@ require_relative "../test_helper"
module Prism
class StaticLiteralsTest < TestCase
+ def test_concatenanted_string_literal_is_not_static
+ node = Prism.parse_statement("'a' 'b'")
+ refute_predicate node, :static_literal?
+ end
+
def test_static_literals
assert_warning("1")
assert_warning("0xA", "10", "10")