From 1161edfa335bf56265e1f4ed17d8d61ab81cd56a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tinjo=20Sch=C3=B6ni?= <32767367+tscni@users.noreply.github.com> Date: Tue, 20 Jun 2023 00:13:13 +0200 Subject: [PATCH] Invalidate cached methods when referenced files are deleted --- src/Psalm/Internal/Codebase/Analyzer.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Psalm/Internal/Codebase/Analyzer.php b/src/Psalm/Internal/Codebase/Analyzer.php index 6378e4847..ba0209ea6 100644 --- a/src/Psalm/Internal/Codebase/Analyzer.php +++ b/src/Psalm/Internal/Codebase/Analyzer.php @@ -687,6 +687,16 @@ class Analyzer } } + // This could be optimized by storing method references to files + foreach ($file_reference_provider->getDeletedReferencedFiles() as $deleted_file) { + foreach ($file_reference_provider->getFilesReferencingFile($deleted_file) as $file_referencing_deleted) { + $methods_referencing_deleted = $this->analyzed_methods[$file_referencing_deleted] ?? []; + foreach ($methods_referencing_deleted as $method_referencing_deleted => $_) { + $newly_invalidated_methods[$method_referencing_deleted] = true; + } + } + } + foreach ($newly_invalidated_methods as $method_id => $_) { foreach ($method_references_to_class_members as $i => $_) { unset($method_references_to_class_members[$i][$method_id]);