mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Fix #3177 - prevent crash by using inherited templates
This commit is contained in:
parent
5180ce1f54
commit
b0455adced
@ -64,7 +64,8 @@ class ForeachAnalyzer
|
||||
$var_comments = CommentAnalyzer::getTypeFromComment(
|
||||
$doc_comment,
|
||||
$statements_analyzer->getSource(),
|
||||
$statements_analyzer->getSource()->getAliases()
|
||||
$statements_analyzer->getSource()->getAliases(),
|
||||
$statements_analyzer->getTemplateTypeMap() ?: []
|
||||
);
|
||||
} catch (DocblockParseException $e) {
|
||||
if (IssueBuffer::accepts(
|
||||
|
@ -2611,6 +2611,50 @@ class ClassTemplateTest extends TestCase
|
||||
}
|
||||
}'
|
||||
],
|
||||
'noCrashTemplateInsideGenerator' => [
|
||||
'<?php
|
||||
namespace Foo;
|
||||
|
||||
/**
|
||||
* @template T
|
||||
*/
|
||||
final class Set
|
||||
{
|
||||
/** @var \Iterator<T> */
|
||||
private \Iterator $values;
|
||||
|
||||
/**
|
||||
* @param \Iterator<T> $values
|
||||
*/
|
||||
public function __construct(\Iterator $values)
|
||||
{
|
||||
$this->values = $values;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param T $element
|
||||
*
|
||||
* @return self<T>
|
||||
*/
|
||||
public function __invoke($element): self
|
||||
{
|
||||
return new self(
|
||||
(
|
||||
function($values, $element): \Generator {
|
||||
/** @var T $value */
|
||||
foreach ($values as $value) {
|
||||
yield $value;
|
||||
}
|
||||
|
||||
yield $element;
|
||||
}
|
||||
)($this->values, $element),
|
||||
);
|
||||
}
|
||||
}',
|
||||
[],
|
||||
['MissingClosureParamType']
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user