From e0b315f5a9afe1dc921e184b139ffbd05866df36 Mon Sep 17 00:00:00 2001 From: kkmuffme <11071985+kkmuffme@users.noreply.github.com> Date: Wed, 15 Nov 2023 10:11:46 +0100 Subject: [PATCH] Fix for classes what https://github.com/vimeo/psalm/pull/8503 fixed for functions (as some issues didn't report for other reasons, which were solved since then) --- .../PhpVisitor/Reflector/ClassLikeNodeScanner.php | 9 +++++++++ src/Psalm/Internal/PhpVisitor/ReflectorVisitor.php | 6 +++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Psalm/Internal/PhpVisitor/Reflector/ClassLikeNodeScanner.php b/src/Psalm/Internal/PhpVisitor/Reflector/ClassLikeNodeScanner.php index c4a6e3b491a..87da361b2e1 100644 --- a/src/Psalm/Internal/PhpVisitor/Reflector/ClassLikeNodeScanner.php +++ b/src/Psalm/Internal/PhpVisitor/Reflector/ClassLikeNodeScanner.php @@ -176,6 +176,15 @@ public function start(PhpParser\Node\Stmt\ClassLike $node): ?bool if ($this->codebase->classlike_storage_provider->has($fq_classlike_name_lc)) { $duplicate_storage = $this->codebase->classlike_storage_provider->get($fq_classlike_name_lc); + // don't override data from files that are getting analyzed with data from stubs + // if the stubs contain the same class + if (!$duplicate_storage->stubbed + && $this->codebase->register_stub_files + && $duplicate_storage->stmt_location + && $this->config->isInProjectDirs($duplicate_storage->stmt_location->file_path)) { + return false; + } + if (!$this->codebase->register_stub_files) { if (!$duplicate_storage->stmt_location || $duplicate_storage->stmt_location->file_path !== $this->file_path diff --git a/src/Psalm/Internal/PhpVisitor/ReflectorVisitor.php b/src/Psalm/Internal/PhpVisitor/ReflectorVisitor.php index 85d538c3ea8..c8a05ea6d65 100644 --- a/src/Psalm/Internal/PhpVisitor/ReflectorVisitor.php +++ b/src/Psalm/Internal/PhpVisitor/ReflectorVisitor.php @@ -152,13 +152,13 @@ public function enterNode(PhpParser\Node $node): ?int $this->namespace_name, ); - $this->classlike_node_scanners[] = $classlike_node_scanner; - if ($classlike_node_scanner->start($node) === false) { $this->bad_classes[spl_object_id($node)] = true; - return PhpParser\NodeTraverser::DONT_TRAVERSE_CHILDREN; + return PhpParser\NodeTraverser::DONT_TRAVERSE_CURRENT_AND_CHILDREN; } + $this->classlike_node_scanners[] = $classlike_node_scanner; + $this->type_aliases = array_merge($this->type_aliases, $classlike_node_scanner->type_aliases); } elseif ($node instanceof PhpParser\Node\Stmt\TryCatch) { foreach ($node->catches as $catch) {