mirror of
https://github.com/danog/psalm.git
synced 2024-11-27 12:55:26 +01:00
Merge pull request #7311 from orklah/inArrayAssertionOnTemplate
don't crash when pushing a template to in_array
This commit is contained in:
commit
3dbc039415
@ -3556,7 +3556,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 {
|
||||
|
@ -1898,6 +1898,29 @@ class AssertAnnotationTest extends TestCase
|
||||
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
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user