Skip to content

Commit 26af5fb

Browse files
committed
Preserve Nodes.InterpolatedStringNode's FROZEN flag when all the parts are String literals
1 parent 1f59f71 commit 26af5fb

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
subject: "String"
2+
description: "2 string literals concatenated at parse/translation time / with frozen_string_literal: true"
3+
notes: >
4+
Result string should be frozen and represented as a FrozenStringLiteralNode node
5+
focused_on_node: "org.truffleruby.language.literal.FrozenStringLiteralNode"
6+
ruby: |
7+
# frozen_string_literal: true
8+
"foo" "bar"
9+
ast: |
10+
FrozenStringLiteralNode
11+
attributes:
12+
definition = "expression" (ASCII-8BIT)
13+
flags = 0
14+
frozenString = "foobar" (UTF-8)
15+
sourceCharIndex = 30
16+
sourceLength = 11

src/main/java/org/truffleruby/parser/YARPTranslator.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2510,7 +2510,8 @@ private static Nodes.StringNode concatStringNodes(Nodes.InterpolatedStringNode n
25102510
int start = parts[0].startOffset;
25112511
var last = ArrayUtils.getLast(parts);
25122512
int length = last.endOffset() - start;
2513-
return new Nodes.StringNode(NO_FLAGS, concatenated, start, length);
2513+
short flags = node.isFrozen() ? Nodes.StringFlags.FROZEN : NO_FLAGS;
2514+
return new Nodes.StringNode(flags, concatenated, start, length);
25142515
}
25152516

25162517
/** Translate parts of interpolated String, Symbol or Regexp */

0 commit comments

Comments
 (0)