From 2562e37e60b37e9f89475c7ec6ca7ccc66b77688 Mon Sep 17 00:00:00 2001 From: Bruce Weirdan Date: Sat, 31 Jul 2021 23:05:15 +0300 Subject: [PATCH] Scan preloaded stubs earlier This should prevent Psalm from sometimes marking user-defined classes as built-in. Fixes vimeo/psalm#5126 Fixes vimeo/psalm#5626 --- src/Psalm/Internal/Analyzer/ProjectAnalyzer.php | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php b/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php index 837d945dc..d19e264e3 100644 --- a/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php @@ -582,6 +582,7 @@ class ProjectAnalyzer || $deleted_files === null || count($diff_files) > 200 ) { + $this->config->visitPreloadedStubFiles($this->codebase, $this->progress); $this->visitAutoloadFiles(); $this->codebase->scanner->addFilesToShallowScan($this->extra_files); @@ -590,8 +591,6 @@ class ProjectAnalyzer $this->config->initializePlugins($this); - $this->config->visitPreloadedStubFiles($this->codebase, $this->progress); - $this->codebase->scanFiles($this->threads); $this->codebase->infer_types_from_usage = true; @@ -608,14 +607,13 @@ class ProjectAnalyzer $file_list = array_diff($file_list, $deleted_files); if ($file_list) { + $this->config->visitPreloadedStubFiles($this->codebase, $this->progress); $this->visitAutoloadFiles(); $this->checkDiffFilesWithConfig($this->config, $file_list); $this->config->initializePlugins($this); - $this->config->visitPreloadedStubFiles($this->codebase, $this->progress); - $this->codebase->scanFiles($this->threads); } else { $diff_no_files = true; @@ -989,14 +987,14 @@ class ProjectAnalyzer { $this->file_reference_provider->loadReferenceCache(); + $this->config->visitPreloadedStubFiles($this->codebase, $this->progress); + $this->checkDirWithConfig($dir_name, $this->config, true); $this->progress->startScanningFiles(); $this->config->initializePlugins($this); - $this->config->visitPreloadedStubFiles($this->codebase, $this->progress); - $this->codebase->scanFiles($this->threads); $this->config->visitStubFiles($this->codebase, $this->progress); @@ -1116,6 +1114,8 @@ class ProjectAnalyzer { $this->progress->debug('Checking ' . $file_path . "\n"); + $this->config->visitPreloadedStubFiles($this->codebase, $this->progress); + $this->config->hide_external_errors = $this->config->isInProjectDirs($file_path); $this->codebase->addFilesToAnalyze([$file_path => $file_path]); @@ -1126,8 +1126,6 @@ class ProjectAnalyzer $this->config->initializePlugins($this); - $this->config->visitPreloadedStubFiles($this->codebase, $this->progress); - $this->codebase->scanFiles($this->threads); $this->config->visitStubFiles($this->codebase, $this->progress); @@ -1147,6 +1145,7 @@ class ProjectAnalyzer */ public function checkPaths(array $paths_to_check): void { + $this->config->visitPreloadedStubFiles($this->codebase, $this->progress); $this->visitAutoloadFiles(); $this->codebase->scanner->addFilesToShallowScan($this->extra_files); @@ -1168,7 +1167,6 @@ class ProjectAnalyzer $this->config->initializePlugins($this); - $this->config->visitPreloadedStubFiles($this->codebase, $this->progress); $this->codebase->scanFiles($this->threads);