From 1db76bd737213afc62016d18c16a2563c723363b Mon Sep 17 00:00:00 2001 From: Matt Brown Date: Fri, 11 Dec 2020 10:04:28 -0500 Subject: [PATCH] =?UTF-8?q?Fix=20#4829=20=E2=80=93=20don=E2=80=99t=20crash?= =?UTF-8?q?=20when=20yielding=20non-existent=20class?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Statements/Expression/YieldAnalyzer.php | 4 ++++ tests/GeneratorTest.php | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/YieldAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/YieldAnalyzer.php index 5613655f3..fa26f38fb 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/YieldAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/YieldAnalyzer.php @@ -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) { diff --git a/tests/GeneratorTest.php b/tests/GeneratorTest.php index 813839f9b..0f7909b3a 100644 --- a/tests/GeneratorTest.php +++ b/tests/GeneratorTest.php @@ -252,6 +252,24 @@ class GeneratorTest extends TestCase } echo json_encode(iterator_to_array(getIteratorOrAggregate()));' ], + 'yieldNonExistentClass' => [ + '