Skip to content

Commit a78c521

Browse files
Validate PinnedVariableNode
1 parent a3a218b commit a78c521

2 files changed

Lines changed: 4 additions & 0 deletions

File tree

src/prism.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16871,6 +16871,9 @@ parse_pattern_primitive(pm_parser_t *parser, pm_constant_id_list_t *captures, pm
1687116871
// not understood. We'll create a missing node and return that.
1687216872
pm_parser_err_token(parser, &operator, PM_ERR_PATTERN_EXPRESSION_AFTER_PIN);
1687316873
pm_node_t *variable = UP(pm_missing_node_create(parser, operator.start, operator.end));
16874+
PM_VALIDATE_NODE_TYPE(parser, variable,
16875+
PM_LOCAL_VARIABLE_READ_NODE, PM_INSTANCE_VARIABLE_READ_NODE, PM_CLASS_VARIABLE_READ_NODE, PM_GLOBAL_VARIABLE_READ_NODE,
16876+
PM_BACK_REFERENCE_READ_NODE, PM_NUMBERED_REFERENCE_READ_NODE, PM_IT_LOCAL_VARIABLE_READ_NODE);
1687416877
return UP(pm_pinned_variable_node_create(parser, &operator, variable));
1687516878
}
1687616879
}

test/prism/result/error_recovery_test.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ def test_pinned_variable_node_variable_missing
195195

196196
node = result.value.statements.body.first.pattern
197197
assert_kind_of ErrorRecoveryNode, node.variable
198+
assert_nil node.variable.child
198199
end
199200

200201
def test_rescue_node_reference_back_reference

0 commit comments

Comments
 (0)