Skip to content

Commit e8f784e

Browse files
authored
Merge pull request ruby#3499 from ruby/concat-xstrings
Make xstrings concat syntax error
2 parents cec425c + f734350 commit e8f784e

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

config.yml

+1
Original file line numberDiff line numberDiff line change
@@ -3145,6 +3145,7 @@ nodes:
31453145
- EmbeddedStatementsNode
31463146
- EmbeddedVariableNode
31473147
- InterpolatedStringNode # `"a" "#{b}"`
3148+
- on error: XStringNode # `<<`FOO` "bar"
31483149
- name: closing_loc
31493150
type: location?
31503151
newline: parts

src/prism.c

+10
Original file line numberDiff line numberDiff line change
@@ -5328,6 +5328,12 @@ pm_interpolated_string_node_append(pm_interpolated_string_node_t *node, pm_node_
53285328
// should clear the mutability flags.
53295329
CLEAR_FLAGS(node);
53305330
break;
5331+
case PM_X_STRING_NODE:
5332+
case PM_INTERPOLATED_X_STRING_NODE:
5333+
// If this is an x string, then this is a syntax error. But we want
5334+
// to handle it here so that we don't fail the assertion.
5335+
CLEAR_FLAGS(node);
5336+
break;
53315337
default:
53325338
assert(false && "unexpected node type");
53335339
break;
@@ -16828,6 +16834,10 @@ parse_strings(pm_parser_t *parser, pm_node_t *current, bool accepts_label, uint1
1682816834
// If we haven't already created our container for concatenation,
1682916835
// we'll do that now.
1683016836
if (!concating) {
16837+
if (!PM_NODE_TYPE_P(current, PM_STRING_NODE) && !PM_NODE_TYPE_P(current, PM_INTERPOLATED_STRING_NODE)) {
16838+
pm_parser_err_node(parser, current, PM_ERR_STRING_CONCATENATION);
16839+
}
16840+
1683116841
concating = true;
1683216842
pm_token_t bounds = not_provided(parser);
1683316843

test/prism/errors/xstring_concat.txt

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<<`EOC` "bar"
2+
^~~~~~~ expected a string for concatenation
3+
echo foo
4+
EOC
5+

0 commit comments

Comments
 (0)