@@ -1092,10 +1092,13 @@ static VALUE parse_intersection(parserstate *state) {
10921092 rg .start = state -> next_token .range .start ;
10931093
10941094 VALUE type = parse_optional (state );
1095- VALUE intersection_types = rb_ary_new () ;
1095+ VALUE intersection_types = EMPTY_ARRAY ;
10961096
1097- rb_ary_push (intersection_types , type );
10981097 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+ }
10991102 parser_advance (state );
11001103 rb_ary_push (intersection_types , parse_optional (state ));
11011104 }
@@ -1119,10 +1122,13 @@ VALUE parse_type(parserstate *state) {
11191122 rg .start = state -> next_token .range .start ;
11201123
11211124 VALUE type = parse_intersection (state );
1122- VALUE union_types = rb_ary_new () ;
1125+ VALUE union_types = EMPTY_ARRAY ;
11231126
1124- rb_ary_push (union_types , type );
11251127 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+ }
11261132 parser_advance (state );
11271133 rb_ary_push (union_types , parse_intersection (state ));
11281134 }
0 commit comments