@@ -128,4 +128,45 @@ public function testSetOffsetExplicitlyWithGap(array $list): void
128128 assertType ('non-empty-array<int<0, max>, int>&hasOffsetValue(0, 17)&hasOffsetValue(2, 21) ' , $ list );
129129 }
130130
131+ /** @param list<int> $list */
132+ function testAppendImmediatelyAfterLastElement (array $ list ): void
133+ {
134+ assertType ('list<int> ' , $ list );
135+ $ list [0 ] = 17 ;
136+ assertType ('non-empty-list<int>&hasOffsetValue(0, 17) ' , $ list );
137+ $ list [1 ] = 19 ;
138+ assertType ('non-empty-list<int>&hasOffsetValue(0, 17)&hasOffsetValue(1, 19) ' , $ list );
139+ $ list [2 ] = 21 ;
140+ assertType ('non-empty-list<int>&hasOffsetValue(0, 17)&hasOffsetValue(1, 19)&hasOffsetValue(2, 21) ' , $ list );
141+ $ list [3 ] = 21 ;
142+ assertType ('non-empty-list<int>&hasOffsetValue(0, 17)&hasOffsetValue(1, 19)&hasOffsetValue(2, 21)&hasOffsetValue(3, 21) ' , $ list );
143+
144+ // hole in the list -> turns it into a array
145+
146+ $ list [5 ] = 21 ;
147+ assertType ('non-empty-array<int<0, max>, int>&hasOffsetValue(0, 17)&hasOffsetValue(1, 19)&hasOffsetValue(2, 21)&hasOffsetValue(3, 21)&hasOffsetValue(5, 21) ' , $ list );
148+ }
149+
150+
151+ /** @param list<int> $list */
152+ function testKeepListAfterLast (array $ list ): void
153+ {
154+ if (isset ($ list [5 ])) {
155+ assertType ('non-empty-list<int>&hasOffsetValue(5, int) ' , $ list );
156+ $ list [6 ] = 21 ;
157+ assertType ('non-empty-list<int>&hasOffsetValue(5, int)&hasOffsetValue(6, 21) ' , $ list );
158+ }
159+ assertType ('list<int> ' , $ list );
160+ }
161+
162+ /** @param list<int> $list */
163+ function testKeepListAfterLastArrayKey (array $ list ): void
164+ {
165+ if (array_key_exists (5 , $ list ) && is_int ($ list [5 ])) {
166+ assertType ('non-empty-list<int>&hasOffsetValue(5, int) ' , $ list );
167+ $ list [6 ] = 21 ;
168+ assertType ('non-empty-list<int>&hasOffsetValue(5, int)&hasOffsetValue(6, 21) ' , $ list );
169+ }
170+ assertType ('list<int> ' , $ list );
171+ }
131172}
0 commit comments