@@ -1088,59 +1088,49 @@ static VALUE parse_simple(parserstate *state) {
10881088 | {} <optional>
10891089*/
10901090static VALUE parse_intersection (parserstate * state ) {
1091- range rg ;
1092- rg .start = state -> next_token .range .start ;
1093-
1091+ position start = state -> next_token .range .start ;
10941092 VALUE type = parse_optional (state );
1095- VALUE intersection_types = EMPTY_ARRAY ;
1093+ if (state -> next_token .type != pAMP ) {
1094+ return type ;
1095+ }
10961096
1097+ VALUE intersection_types = rb_ary_new ();
1098+ rb_ary_push (intersection_types , type );
10971099 while (state -> next_token .type == pAMP ) {
1098- if (intersection_types == EMPTY_ARRAY ) {
1099- melt_array (& intersection_types );
1100- rb_ary_push (intersection_types , type );
1101- }
11021100 parser_advance (state );
11031101 rb_ary_push (intersection_types , parse_optional (state ));
11041102 }
1105-
1106- rg .end = state -> current_token .range .end ;
1107-
1108- if (rb_array_len (intersection_types ) > 1 ) {
1109- VALUE location = rbs_new_location (state -> buffer , rg );
1110- type = rbs_intersection (intersection_types , location );
1111- }
1112-
1113- return type ;
1103+ range rg = (range ) {
1104+ .start = start ,
1105+ .end = state -> current_token .range .end ,
1106+ };
1107+ VALUE location = rbs_new_location (state -> buffer , rg );
1108+ return rbs_intersection (intersection_types , location );
11141109}
11151110
11161111/*
11171112 union ::= {} intersection '|' ... '|' <intersection>
11181113 | {} <intersection>
11191114*/
11201115VALUE parse_type (parserstate * state ) {
1121- range rg ;
1122- rg .start = state -> next_token .range .start ;
1123-
1116+ position start = state -> next_token .range .start ;
11241117 VALUE type = parse_intersection (state );
1125- VALUE union_types = EMPTY_ARRAY ;
1118+ if (state -> next_token .type != pBAR ) {
1119+ return type ;
1120+ }
11261121
1122+ VALUE union_types = rb_ary_new ();
1123+ rb_ary_push (union_types , type );
11271124 while (state -> next_token .type == pBAR ) {
1128- if (union_types == EMPTY_ARRAY ) {
1129- melt_array (& union_types );
1130- rb_ary_push (union_types , type );
1131- }
11321125 parser_advance (state );
11331126 rb_ary_push (union_types , parse_intersection (state ));
11341127 }
1135-
1136- rg .end = state -> current_token .range .end ;
1137-
1138- if (rb_array_len (union_types ) > 1 ) {
1139- VALUE location = rbs_new_location (state -> buffer , rg );
1140- type = rbs_union (union_types , location );
1141- }
1142-
1143- return type ;
1128+ range rg = (range ) {
1129+ .start = start ,
1130+ .end = state -> current_token .range .end ,
1131+ };
1132+ VALUE location = rbs_new_location (state -> buffer , rg );
1133+ return rbs_union (union_types , location );
11441134}
11451135
11461136/*
0 commit comments