Skip to content

Commit bc5f85d

Browse files
Validate InterpolatedStringNode
1 parent ff4eefd commit bc5f85d

3 files changed

Lines changed: 9 additions & 18 deletions

File tree

config.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3301,10 +3301,7 @@ nodes:
33013301
- EmbeddedStatementsNode
33023302
- EmbeddedVariableNode
33033303
- InterpolatedStringNode # `"a" "#{b}"`
3304-
- on error: XStringNode # `<<`FOO` "bar"
3305-
- on error: InterpolatedXStringNode
3306-
- on error: SymbolNode
3307-
- on error: InterpolatedSymbolNode
3304+
- on error: ErrorRecoveryNode
33083305
- name: closing_loc
33093306
type: location?
33103307
newline: parts

src/prism.c

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4751,7 +4751,7 @@ pm_interpolated_node_append(pm_node_t *node, pm_node_list_t *parts, pm_node_t *p
47514751
pm_node_flag_unset(UP(node), PM_NODE_FLAG_STATIC_LITERAL);
47524752
break;
47534753
default:
4754-
assert(false && "unexpected node type");
4754+
pm_node_flag_unset(node, PM_NODE_FLAG_STATIC_LITERAL);
47554755
break;
47564756
}
47574757

@@ -4888,16 +4888,8 @@ pm_interpolated_string_node_append(pm_interpolated_string_node_t *node, pm_node_
48884888
// should clear the mutability flags.
48894889
CLEAR_FLAGS(node);
48904890
break;
4891-
case PM_X_STRING_NODE:
4892-
case PM_INTERPOLATED_X_STRING_NODE:
4893-
case PM_SYMBOL_NODE:
4894-
case PM_INTERPOLATED_SYMBOL_NODE:
4895-
// These will only happen in error cases. But we want to handle it
4896-
// here so that we don't fail the assertion.
4897-
CLEAR_FLAGS(node);
4898-
break;
48994891
default:
4900-
assert(false && "unexpected node type");
4892+
CLEAR_FLAGS(node);
49014893
break;
49024894
}
49034895

@@ -16172,14 +16164,16 @@ parse_strings(pm_parser_t *parser, pm_node_t *current, bool accepts_label, uint1
1617216164
// Otherwise we need to check the type of the node we just parsed.
1617316165
// If it cannot be concatenated with the previous node, then we'll
1617416166
// need to add a syntax error.
16175-
if (!PM_NODE_TYPE_P(node, PM_STRING_NODE) && !PM_NODE_TYPE_P(node, PM_INTERPOLATED_STRING_NODE)) {
16167+
PM_VALIDATE_NODE_TYPE(parser, node, PM_STRING_NODE, PM_INTERPOLATED_STRING_NODE);
16168+
if (PM_NODE_TYPE_P(node, PM_ERROR_RECOVERY_NODE)) {
1617616169
pm_parser_err_node(parser, node, PM_ERR_STRING_CONCATENATION);
1617716170
}
1617816171

1617916172
// If we haven't already created our container for concatenation,
1618016173
// we'll do that now.
1618116174
if (!concating) {
16182-
if (!PM_NODE_TYPE_P(current, PM_STRING_NODE) && !PM_NODE_TYPE_P(current, PM_INTERPOLATED_STRING_NODE)) {
16175+
PM_VALIDATE_NODE_TYPE(parser, current, PM_STRING_NODE, PM_INTERPOLATED_STRING_NODE);
16176+
if (PM_NODE_TYPE_P(current, PM_ERROR_RECOVERY_NODE)) {
1618316177
pm_parser_err_node(parser, current, PM_ERR_STRING_CONCATENATION);
1618416178
}
1618516179

test/prism/result/error_recovery_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,15 @@ def test_interpolated_string_node_parts_xstring
8181
refute result.success?
8282

8383
node = result.value.statements.body.first
84-
assert node.parts.any? { |part| part.is_a?(XStringNode) }
84+
assert node.parts.any? { |part| part.is_a?(ErrorRecoveryNode) && part.child.is_a?(XStringNode) }
8585
end
8686

8787
def test_interpolated_string_node_parts_interpolated_xstring
8888
result = Prism.parse("<<~`FOO` \"bar\"\n\#{ls}\nFOO\n")
8989
refute result.success?
9090

9191
node = result.value.statements.body.first
92-
assert node.parts.any? { |part| part.is_a?(InterpolatedXStringNode) }
92+
assert node.parts.any? { |part| part.is_a?(ErrorRecoveryNode) && part.child.is_a?(InterpolatedXStringNode) }
9393
end
9494

9595
def test_module_node_constant_path_missing

0 commit comments

Comments
 (0)