summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Newton <kddnewton@gmail.com>2024-02-27 09:44:13 -0500
committergit <svn-admin@ruby-lang.org>2024-02-27 16:05:02 +0000
commitfc36882713c7f86dcbec84c996b09a9c79a2d71f (patch)
tree6288aca81a22002ff23fc3f39afe70695a3838dc
parent2396b7a62fc12ef70933872667020b3784cb9e2e (diff)
[ruby/prism] Ensure symbol nodes not in interpolated symbol
https://github.com/ruby/prism/commit/e1a9a1d478
-rw-r--r--prism/prism.c15
-rw-r--r--test/prism/snapshots/spanning_heredoc.txt6
2 files changed, 14 insertions, 7 deletions
diff --git a/prism/prism.c b/prism/prism.c
index 0cedf924e4..7c41b1670e 100644
--- a/prism/prism.c
+++ b/prism/prism.c
@@ -16523,15 +16523,22 @@ parse_expression_prefix(pm_parser_t *parser, pm_binding_power_t binding_power, b
pm_interpolated_symbol_node_append((pm_interpolated_symbol_node_t *) current, string);
} else if (PM_NODE_TYPE_P(current, PM_SYMBOL_NODE)) {
- // If we hit string content and the current node is a string node,
+ // If we hit string content and the current node is a symbol node,
// then we need to convert the current node into an interpolated
// string and add the string content to the list of child nodes.
- pm_node_t *string = (pm_node_t *) pm_string_node_create_current_string(parser, &opening, &parser->previous, &closing);
+ pm_symbol_node_t *cast = (pm_symbol_node_t *) current;
+ pm_token_t bounds = not_provided(parser);
+
+ pm_token_t content = { .type = PM_TOKEN_STRING_CONTENT, .start = cast->value_loc.start, .end = cast->value_loc.end };
+ pm_node_t *first_string = (pm_node_t *) pm_string_node_create_unescaped(parser, &bounds, &content, &bounds, &cast->unescaped);
+ pm_node_t *second_string = (pm_node_t *) pm_string_node_create_current_string(parser, &opening, &parser->previous, &closing);
parser_lex(parser);
pm_interpolated_symbol_node_t *interpolated = pm_interpolated_symbol_node_create(parser, &opening, NULL, &closing);
- pm_interpolated_symbol_node_append(interpolated, current);
- pm_interpolated_symbol_node_append(interpolated, string);
+ pm_interpolated_symbol_node_append(interpolated, first_string);
+ pm_interpolated_symbol_node_append(interpolated, second_string);
+
+ free(current);
current = (pm_node_t *) interpolated;
} else {
assert(false && "unreachable");
diff --git a/test/prism/snapshots/spanning_heredoc.txt b/test/prism/snapshots/spanning_heredoc.txt
index da930499d6..90297d2282 100644
--- a/test/prism/snapshots/spanning_heredoc.txt
+++ b/test/prism/snapshots/spanning_heredoc.txt
@@ -298,10 +298,10 @@
│ │ │ └── @ InterpolatedSymbolNode (location: (48,12)-(48,14))
│ │ │ ├── opening_loc: ∅
│ │ │ ├── parts: (length: 2)
- │ │ │ │ ├── @ SymbolNode (location: (48,12)-(48,14))
- │ │ │ │ │ ├── flags: forced_us_ascii_encoding
+ │ │ │ │ ├── @ StringNode (location: (48,12)-(48,14))
+ │ │ │ │ │ ├── flags: ∅
│ │ │ │ │ ├── opening_loc: ∅
- │ │ │ │ │ ├── value_loc: (48,12)-(48,14) = "p\\"
+ │ │ │ │ │ ├── content_loc: (48,12)-(48,14) = "p\\"
│ │ │ │ │ ├── closing_loc: ∅
│ │ │ │ │ └── unescaped: "p\n"
│ │ │ │ └── @ StringNode (location: (48,12)-(48,14))