diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/AssertionFinder.php b/src/Psalm/Internal/Analyzer/Statements/Expression/AssertionFinder.php index c5854130a2c..035effe4fc2 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/AssertionFinder.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/AssertionFinder.php @@ -3556,7 +3556,7 @@ private static function getInarrayAssertions( // - The array may have one of the types but not the others. // // NOTE: the negation of the negation is the original assertion. - if ($value_type->getId() !== '' && !$value_type->isMixed()) { + if ($value_type->getId() !== '' && !$value_type->isMixed() && !$value_type->hasTemplate()) { $assertions[] = 'in-array-' . $value_type->getId(); } } else { diff --git a/tests/AssertAnnotationTest.php b/tests/AssertAnnotationTest.php index ade990073f5..92f47dfa3a2 100644 --- a/tests/AssertAnnotationTest.php +++ b/tests/AssertAnnotationTest.php @@ -1898,6 +1898,29 @@ function assertBarNotNull(Foo $foo): bool function requiresString(string $_str): void {} ', ], + 'assertInArrayWithTemplateDontCrash' => [ + ' $objects + * @return array + */ + private function uniquateObjects(array $objects) : array + { + $uniqueObjects = []; + foreach ($objects as $object) { + if (in_array($object, $uniqueObjects, true)) { + continue; + } + $uniqueObjects[] = $object; + } + + return $uniqueObjects; + } + } + ', + ], 'assertionOnMagicProperty' => [ '