1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-27 04:45:20 +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
parent a27c674cee
commit cc1c643168
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']
],
];
}