@@ -746,7 +746,7 @@ typedef struct {
746746 | {} self_type_binding? `->` <optional>
747747*/
748748NODISCARD
749- static bool parse_function (rbs_parser_t * parser , bool accept_type_binding , parse_function_result * * result , bool self_allowed , bool classish_allowed ) {
749+ static bool parse_function (rbs_parser_t * parser , bool accept_type_binding , bool block_allowed , parse_function_result * * result , bool self_allowed , bool classish_allowed ) {
750750 rbs_node_t * function = NULL ;
751751 rbs_types_block_t * block = NULL ;
752752 rbs_node_t * function_self_type = NULL ;
@@ -777,6 +777,11 @@ static bool parse_function(rbs_parser_t *parser, bool accept_type_binding, parse
777777 bool required = true;
778778 rbs_range_t block_range ;
779779
780+ if (!block_allowed && (parser -> next_token .type == pLBRACE || (parser -> next_token .type == pQUESTION && parser -> next_token2 .type == pLBRACE ))) {
781+ rbs_parser_set_error (parser , parser -> next_token , true, "block is not allowed in this context" );
782+ return false;
783+ }
784+
780785 if (parser -> next_token .type == pQUESTION && parser -> next_token2 .type == pLBRACE ) {
781786 // Optional block
782787 block_range .start = parser -> next_token .range .start ;
@@ -865,7 +870,7 @@ NODISCARD
865870static bool parse_proc_type (rbs_parser_t * parser , rbs_types_proc_t * * proc , bool self_allowed , bool classish_allowed ) {
866871 rbs_position_t start = parser -> current_token .range .start ;
867872 parse_function_result * result = rbs_allocator_alloc (ALLOCATOR (), parse_function_result );
868- CHECK_PARSE (parse_function (parser , true, & result , self_allowed , classish_allowed ));
873+ CHECK_PARSE (parse_function (parser , true, true, & result , self_allowed , classish_allowed ));
869874
870875 rbs_position_t end = parser -> current_token .range .end ;
871876 rbs_location_range range = { .start_char = start .char_pos , .start_byte = start .byte_pos , .end_char = end .char_pos , .end_byte = end .byte_pos };
@@ -1597,7 +1602,7 @@ bool rbs_parse_method_type(rbs_parser_t *parser, rbs_method_type_t **method_type
15971602 type_range .start = parser -> next_token .range .start ;
15981603
15991604 parse_function_result * result = rbs_allocator_alloc (ALLOCATOR (), parse_function_result );
1600- CHECK_PARSE (parse_function (parser , false, & result , true, classish_allowed ));
1605+ CHECK_PARSE (parse_function (parser , false, true, & result , true, classish_allowed ));
16011606
16021607 CHECK_PARSE (parser_pop_typevar_table (parser ));
16031608
@@ -4017,12 +4022,7 @@ static bool parse_inline_leading_annotation(rbs_parser_t *parser, rbs_ast_ruby_a
40174022 type_range .start = parser -> next_token .range .start ;
40184023
40194024 parse_function_result * result = rbs_allocator_alloc (ALLOCATOR (), parse_function_result );
4020- if (!parse_function (parser , true, & result , true, true)) {
4021- return false;
4022- }
4023-
4024- if (result -> block != NULL ) {
4025- rbs_parser_set_error (parser , parser -> current_token , true, "block type annotation cannot have a nested block" );
4025+ if (!parse_function (parser , true, false, & result , true, true)) {
40264026 return false;
40274027 }
40284028
0 commit comments