diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/AssertionFinder.php b/src/Psalm/Internal/Analyzer/Statements/Expression/AssertionFinder.php index 87706f98c..77f961884 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/AssertionFinder.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/AssertionFinder.php @@ -3558,7 +3558,7 @@ class AssertionFinder // - 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/stubs/Reflection.phpstub b/stubs/Reflection.phpstub index ece7ca8ae..15df6c68d 100644 --- a/stubs/Reflection.phpstub +++ b/stubs/Reflection.phpstub @@ -103,7 +103,7 @@ class ReflectionMethod implements Reflector public function isStatic(): bool {} } -class ReflectionClassConstant +class ReflectionClassConstant implements Reflector { /** * @since 8.0 @@ -117,7 +117,7 @@ class ReflectionClassConstant /** * @psalm-immutable */ -class ReflectionParameter { +class ReflectionParameter implements Reflector { /** * @psalm-assert-if-true ReflectionType $this->getType() */ diff --git a/tests/AssertAnnotationTest.php b/tests/AssertAnnotationTest.php index ade990073..92f47dfa3 100644 --- a/tests/AssertAnnotationTest.php +++ b/tests/AssertAnnotationTest.php @@ -1898,6 +1898,29 @@ class AssertAnnotationTest extends TestCase 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' => [ '