1
0
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:
Brown 2020-04-18 11:48:22 -04:00
parent 5180ce1f54
commit b0455adced
2 changed files with 46 additions and 1 deletions

View File

@ -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(

View File

@ -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']
],
];
}