mirror of
https://github.com/danog/psalm.git
synced 2024-11-26 20:34:47 +01:00
Always set templated types as being from docblocks
This commit is contained in:
parent
cff7f35d00
commit
cb4691fb44
@ -2014,6 +2014,8 @@ class CallChecker
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$offset_value_type->setFromDocblock();
|
||||
}
|
||||
|
||||
if ($generic_params === null) {
|
||||
|
@ -360,7 +360,8 @@ class Union
|
||||
$this->types[$template_types[$key]] = Atomic::create($template_types[$key]);
|
||||
|
||||
if ($input_type) {
|
||||
$generic_params[$key] = $input_type;
|
||||
$generic_params[$key] = clone $input_type;
|
||||
$generic_params[$key]->setFromDocblock();
|
||||
}
|
||||
} else {
|
||||
$atomic_type->replaceTemplateTypesWithStandins(
|
||||
|
@ -426,6 +426,72 @@ class TemplateTest extends TestCase
|
||||
],
|
||||
'error_levels' => ['MixedAssignment', 'MixedArgument'],
|
||||
],
|
||||
'genericArrayObject' => [
|
||||
'<?php
|
||||
class A {
|
||||
/** @param int[] $ids */
|
||||
public static function loadMultiple(array $ids) : array {
|
||||
return [new static, new static];
|
||||
}
|
||||
}
|
||||
|
||||
class B extends A {}
|
||||
|
||||
/**
|
||||
* @template T as obj
|
||||
*/
|
||||
class Collection extends ArrayObject
|
||||
{
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
protected $type;
|
||||
|
||||
/**
|
||||
* @var int[]
|
||||
*/
|
||||
protected $ids;
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
* @param int[] $ids
|
||||
*
|
||||
* @template-typeof T $type
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(string $type, array $ids)
|
||||
{
|
||||
$this->type = $type;
|
||||
$this->ids = $ids;
|
||||
}
|
||||
|
||||
/**
|
||||
* called to get the collection ready when we go to loop through it
|
||||
*
|
||||
* @return \ArrayIterator
|
||||
*/
|
||||
public function getIterator()
|
||||
{
|
||||
// if we have already processed the items in this collection
|
||||
if (parent::count()) {
|
||||
return parent::getIterator();
|
||||
}
|
||||
|
||||
$class = $this->type;
|
||||
|
||||
$this->exchangeArray($class::loadMultiple($ids));
|
||||
|
||||
return parent::getIterator();
|
||||
}
|
||||
}
|
||||
|
||||
$bs = new Collection(B::class, [1, 2]);
|
||||
|
||||
foreach ($bs as $b) {
|
||||
if (!$b) {}
|
||||
}',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user