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:
parent
972738b772
commit
1db76bd737
@ -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) {
|
||||
|
@ -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']
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user