summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Valentine-House <matt@eightbitraptor.com>2024-01-29 15:29:49 +0000
committerMatt Valentine-House <matt@eightbitraptor.com>2024-01-29 19:13:53 +0000
commitd7501c403130b575219a672073a06792e81dcdb4 (patch)
treebe7928ab583c71dfa08f747f60782a00c9bef339
parent3d3d9e8397a3a84075692b6411647b031a19bf5d (diff)
[PRISM] Fix InterpolatedStringNode
If the first element of an interpolated string node is an embedded statement, CRuby "pre-initializes" the interpolation with a string of known encoding to concat into. This patch replicates thate behaviour in Prism
-rw-r--r--prism_compile.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/prism_compile.c b/prism_compile.c
index 94c0a5f827..c9b3e932b3 100644
--- a/prism_compile.c
+++ b/prism_compile.c
@@ -5365,7 +5365,12 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
}
case PM_INTERPOLATED_STRING_NODE: {
pm_interpolated_string_node_t *interp_string_node = (pm_interpolated_string_node_t *) node;
- int number_of_items_pushed = pm_interpolated_node_compile(&interp_string_node->parts, iseq, dummy_line_node, ret, src, popped, scope_node, parser);
+ int number_of_items_pushed = 0;
+ if (!PM_NODE_TYPE_P(interp_string_node->parts.nodes[0], PM_STRING_NODE)) {
+ ADD_INSN1(ret, &dummy_line_node, putstring, rb_str_new(0, 0));
+ number_of_items_pushed++;
+ }
+ number_of_items_pushed += pm_interpolated_node_compile(&interp_string_node->parts, iseq, dummy_line_node, ret, src, popped, scope_node, parser);
if (number_of_items_pushed > 1) {
ADD_INSN1(ret, &dummy_line_node, concatstrings, INT2FIX(number_of_items_pushed));