1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 12:24:49 +01:00

Fix #4829 – don’t crash when yielding non-existent class

This commit is contained in:
Matt Brown 2020-12-11 10:04:28 -05:00 committed by Daniil Gentili
parent 972738b772
commit 1db76bd737
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
2 changed files with 22 additions and 0 deletions

View File

@ -142,6 +142,10 @@ class YieldAnalyzer
foreach ($expression_type->getAtomicTypes() as $expression_atomic_type) {
if ($expression_atomic_type instanceof Type\Atomic\TNamedObject) {
if (!$codebase->classlikes->classOrInterfaceExists($expression_atomic_type->value)) {
continue;
}
$classlike_storage = $codebase->classlike_storage_provider->get($expression_atomic_type->value);
if ($classlike_storage->yield) {

View File

@ -252,6 +252,24 @@ class GeneratorTest extends TestCase
}
echo json_encode(iterator_to_array(getIteratorOrAggregate()));'
],
'yieldNonExistentClass' => [
'<?php
class T {
private const FACTORIES = [
ClassNotExisting::class,
];
function f() : Generator {
foreach (self::FACTORIES as $f) {
if (class_exists($f)) {
yield new $f();
}
}
}
}',
[],
['UndefinedClass']
],
];
}