[ruby/prism] Make xstrings concat syntax error

https://github.com/ruby/prism/commit/f734350499
This commit is contained in:
Kevin Newton 2025-03-18 11:35:28 -04:00 committed by git
parent f69ad0e810
commit 3d6fc29169
3 changed files with 16 additions and 0 deletions

View File

@ -3140,6 +3140,7 @@ nodes:
- EmbeddedStatementsNode
- EmbeddedVariableNode
- InterpolatedStringNode # `"a" "#{b}"`
- on error: XStringNode # `<<`FOO` "bar"
- name: closing_loc
type: location?
newline: parts

View File

@ -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);

View File

@ -0,0 +1,5 @@
<<`EOC` "bar"
^~~~~~~ expected a string for concatenation
echo foo
EOC