Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

don't crash when pushing a template to in_array #7311

Merged
merged 2 commits into from Jan 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -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 {
Expand Down
23 changes: 23 additions & 0 deletions tests/AssertAnnotationTest.php
Expand Up @@ -1898,6 +1898,29 @@ function assertBarNotNull(Foo $foo): bool
function requiresString(string $_str): void {}
',
],
'assertInArrayWithTemplateDontCrash' => [
'<?php
class A{
/**
* @template T
* @param array<T> $objects
* @return array<T>
*/
private function uniquateObjects(array $objects) : array
{
$uniqueObjects = [];
foreach ($objects as $object) {
if (in_array($object, $uniqueObjects, true)) {
continue;
}
$uniqueObjects[] = $object;
}

return $uniqueObjects;
}
}
',
],
'assertionOnMagicProperty' => [
'<?php
/**
Expand Down