@@ -748,8 +748,12 @@ public function unsetOffset(Type $offsetType, bool $preserveListCertainty = fals
748748 $ newOptionalKeys ,
749749 $ this ->isList ,
750750 in_array ($ i , $ this ->optionalKeys , true ),
751- $ preserveListCertainty ,
752751 );
752+ if (!$ preserveListCertainty ) {
753+ $ newIsList = $ newIsList ->and (TrinaryLogic::createMaybe ());
754+ } elseif ($ this ->isList ->yes () && $ newIsList ->no ()) {
755+ return new NeverType ();
756+ }
753757
754758 return new self ($ newKeyTypes , $ newValueTypes , $ this ->nextAutoIndexes , $ newOptionalKeys , $ newIsList );
755759 }
@@ -791,8 +795,12 @@ public function unsetOffset(Type $offsetType, bool $preserveListCertainty = fals
791795 $ optionalKeys ,
792796 $ this ->isList ,
793797 count ($ optionalKeys ) === count ($ this ->optionalKeys ),
794- $ preserveListCertainty ,
795798 );
799+ if (!$ preserveListCertainty ) {
800+ $ newIsList = $ newIsList ->and (TrinaryLogic::createMaybe ());
801+ } elseif ($ this ->isList ->yes () && $ newIsList ->no ()) {
802+ return new NeverType ();
803+ }
796804
797805 return new self ($ this ->keyTypes , $ this ->valueTypes , $ this ->nextAutoIndexes , $ optionalKeys , $ newIsList );
798806 }
@@ -817,8 +825,12 @@ public function unsetOffset(Type $offsetType, bool $preserveListCertainty = fals
817825 $ optionalKeys ,
818826 $ this ->isList ,
819827 count ($ optionalKeys ) === count ($ this ->optionalKeys ),
820- $ preserveListCertainty ,
821828 );
829+ if (!$ preserveListCertainty ) {
830+ $ newIsList = $ newIsList ->and (TrinaryLogic::createMaybe ());
831+ } elseif ($ this ->isList ->yes () && $ newIsList ->no ()) {
832+ return new NeverType ();
833+ }
822834
823835 return new self ($ this ->keyTypes , $ this ->valueTypes , $ this ->nextAutoIndexes , $ optionalKeys , $ newIsList );
824836 }
@@ -830,7 +842,7 @@ public function unsetOffset(Type $offsetType, bool $preserveListCertainty = fals
830842 * @param list<ConstantIntegerType|ConstantStringType> $newKeyTypes
831843 * @param int[] $newOptionalKeys
832844 */
833- private static function isListAfterUnset (array $ newKeyTypes , array $ newOptionalKeys , TrinaryLogic $ arrayIsList , bool $ unsetOptionalKey, bool $ preserveListCertainty ): TrinaryLogic
845+ private static function isListAfterUnset (array $ newKeyTypes , array $ newOptionalKeys , TrinaryLogic $ arrayIsList , bool $ unsetOptionalKey ): TrinaryLogic
834846 {
835847 if (!$ unsetOptionalKey || $ arrayIsList ->no ()) {
836848 return TrinaryLogic::createNo ();
@@ -854,7 +866,7 @@ private static function isListAfterUnset(array $newKeyTypes, array $newOptionalK
854866 }
855867 }
856868
857- return $ preserveListCertainty ? $ arrayIsList : TrinaryLogic:: createMaybe () ;
869+ return $ arrayIsList ;
858870 }
859871
860872 public function chunkArray (Type $ lengthType , TrinaryLogic $ preserveKeys ): Type
0 commit comments