Skip to content

Commit 937313d

Browse files
committed
Fix up call target node when invalid
When there is an invalid syntax tree, we need to make sure to fill in the required call operator location.
1 parent 8c12a6b commit 937313d

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

src/prism.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3077,6 +3077,17 @@ pm_call_target_node_create(pm_parser_t *parser, pm_call_node_t *target) {
30773077
.message_loc = target->message_loc
30783078
};
30793079

3080+
/* It is possible to get here where we have parsed an invalid syntax tree
3081+
* where the call operator was not present. In that case we will have a
3082+
* problem because it is a required location. In this case we need to fill
3083+
* it in with a fake location so that the syntax tree remains valid. */
3084+
if (node->call_operator_loc.start == NULL) {
3085+
node->call_operator_loc = (pm_location_t) {
3086+
.start = target->base.location.start,
3087+
.end = target->base.location.start
3088+
};
3089+
}
3090+
30803091
// Here we're going to free the target, since it is no longer necessary.
30813092
// However, we don't want to call `pm_node_destroy` because we want to keep
30823093
// around all of its children since we just reused them.

0 commit comments

Comments
 (0)