Skip to content

Commit 553d7ad

Browse files
committed
Fix location parsing for Block
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
1 parent 848c0a3 commit 553d7ad

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/parser.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -722,11 +722,17 @@ static bool parse_function(rbs_parser_t *parser, bool accept_type_binding, parse
722722
}
723723

724724
bool required = true;
725+
rbs_range_t block_range;
726+
725727
if (parser->next_token.type == pQUESTION && parser->next_token2.type == pLBRACE) {
726728
// Optional block
729+
block_range.start = parser->next_token.range.start;
727730
required = false;
728731
rbs_parser_advance(parser);
732+
} else if (parser->next_token.type == pLBRACE) {
733+
block_range.start = parser->next_token.range.start;
729734
}
735+
730736
if (parser->next_token.type == pLBRACE) {
731737
rbs_parser_advance(parser);
732738

@@ -746,9 +752,12 @@ static bool parse_function(rbs_parser_t *parser, bool accept_type_binding, parse
746752
rbs_node_t *block_return_type = NULL;
747753
CHECK_PARSE(parse_optional(parser, &block_return_type));
748754

755+
ADVANCE_ASSERT(parser, pRBRACE);
756+
757+
block_range.end = parser->current_token.range.end;
758+
rbs_location_t *loc = rbs_location_new(ALLOCATOR(), block_range);
759+
749760
rbs_node_t *block_function = NULL;
750-
function_range.end = parser->current_token.range.end;
751-
rbs_location_t *loc = rbs_location_new(ALLOCATOR(), function_range);
752761
if (rbs_is_untyped_params(&block_params)) {
753762
block_function = (rbs_node_t *) rbs_types_untyped_function_new(ALLOCATOR(), loc, block_return_type);
754763
} else {
@@ -767,8 +776,6 @@ static bool parse_function(rbs_parser_t *parser, bool accept_type_binding, parse
767776
}
768777

769778
block = rbs_types_block_new(ALLOCATOR(), loc, block_function, required, self_type);
770-
771-
ADVANCE_ASSERT(parser, pRBRACE);
772779
}
773780

774781
ADVANCE_ASSERT(parser, pARROW);

0 commit comments

Comments
 (0)