diff options
author | Kevin Newton <[email protected]> | 2025-03-18 11:35:28 -0400 |
---|---|---|
committer | git <[email protected]> | 2025-03-18 16:00:03 +0000 |
commit | 3d6fc2916907a351c274449280a82b020208f084 (patch) | |
tree | 80b81c41b1eb304ba277d1821845ea827a179e79 | |
parent | f69ad0e810e1fdc18dc12f77bbecfa49999ef3bf (diff) |
[ruby/prism] Make xstrings concat syntax error
https://github.com/ruby/prism/commit/f734350499
-rw-r--r-- | prism/config.yml | 1 | ||||
-rw-r--r-- | prism/prism.c | 10 | ||||
-rw-r--r-- | test/prism/errors/xstring_concat.txt | 5 |
3 files changed, 16 insertions, 0 deletions
diff --git a/prism/config.yml b/prism/config.yml index cfa3f62f2a..14afabb6e4 100644 --- a/prism/config.yml +++ b/prism/config.yml @@ -3140,6 +3140,7 @@ nodes: - EmbeddedStatementsNode - EmbeddedVariableNode - InterpolatedStringNode # `"a" "#{b}"` + - on error: XStringNode # `<<`FOO` "bar" - name: closing_loc type: location? newline: parts diff --git a/prism/prism.c b/prism/prism.c index cac9832ab6..ed907bd5ac 100644 --- a/prism/prism.c +++ b/prism/prism.c @@ -5328,6 +5328,12 @@ pm_interpolated_string_node_append(pm_interpolated_string_node_t *node, pm_node_ // should clear the mutability flags. CLEAR_FLAGS(node); break; + case PM_X_STRING_NODE: + case PM_INTERPOLATED_X_STRING_NODE: + // If this is an x string, then this is a syntax error. But we want + // to handle it here so that we don't fail the assertion. + CLEAR_FLAGS(node); + break; default: assert(false && "unexpected node type"); break; @@ -16823,6 +16829,10 @@ parse_strings(pm_parser_t *parser, pm_node_t *current, bool accepts_label, uint1 // If we haven't already created our container for concatenation, // we'll do that now. if (!concating) { + if (!PM_NODE_TYPE_P(current, PM_STRING_NODE) && !PM_NODE_TYPE_P(current, PM_INTERPOLATED_STRING_NODE)) { + pm_parser_err_node(parser, current, PM_ERR_STRING_CONCATENATION); + } + concating = true; pm_token_t bounds = not_provided(parser); diff --git a/test/prism/errors/xstring_concat.txt b/test/prism/errors/xstring_concat.txt new file mode 100644 index 0000000000..f4d453d68d --- /dev/null +++ b/test/prism/errors/xstring_concat.txt @@ -0,0 +1,5 @@ +<<`EOC` "bar" +^~~~~~~ expected a string for concatenation +echo foo +EOC + |