diff --git a/src/Psalm/Internal/PhpVisitor/ReflectorVisitor.php b/src/Psalm/Internal/PhpVisitor/ReflectorVisitor.php index a78068513ca..2eefe56e853 100644 --- a/src/Psalm/Internal/PhpVisitor/ReflectorVisitor.php +++ b/src/Psalm/Internal/PhpVisitor/ReflectorVisitor.php @@ -146,6 +146,11 @@ class ReflectorVisitor extends PhpParser\NodeVisitorAbstract implements PhpParse */ private $classlike_type_aliases = []; + /** + * @var array + */ + private $bad_classes = []; + public function __construct( Codebase $codebase, FileStorage $file_storage, @@ -285,7 +290,8 @@ public function enterNode(PhpParser\Node $node): ?int } if ($this->registerClassLike($node) === false) { - return PhpParser\NodeTraverser::STOP_TRAVERSAL; + $this->bad_classes[\spl_object_id($node)] = true; + return PhpParser\NodeTraverser::DONT_TRAVERSE_CHILDREN; } } elseif (($node instanceof PhpParser\Node\Expr\New_ || $node instanceof PhpParser\Node\Expr\Instanceof_ @@ -575,6 +581,10 @@ public function leaveNode(PhpParser\Node $node) return null; } + if (isset($this->bad_classes[\spl_object_id($node)])) { + return null; + } + if (!$this->fq_classlike_names) { throw new \LogicException('$this->fq_classlike_names should not be empty'); } diff --git a/tests/IncludeTest.php b/tests/IncludeTest.php index 63c2ca0221a..16ab5332345 100644 --- a/tests/IncludeTest.php +++ b/tests/IncludeTest.php @@ -599,6 +599,28 @@ function bar(): void {} getcwd() . DIRECTORY_SEPARATOR . 'file2.php', ], ], + 'noCrash' => [ + 'files' => [ + getcwd() . DIRECTORY_SEPARATOR . 'classes.php' => ' ' [ + getcwd() . DIRECTORY_SEPARATOR . 'user.php', + ], + ], ]; }