From ffec25da20c2784677d2545f44332b7660ef8de3 Mon Sep 17 00:00:00 2001 From: Matthew Brown Date: Sun, 14 Apr 2019 12:19:07 -0400 Subject: [PATCH] Fix #1556 - allow internal method calls when checking property initialisation s --- src/Psalm/Internal/Analyzer/ProjectAnalyzer.php | 8 ++++---- tests/PropertyTypeTest.php | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php b/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php index 7ddf664bc..a29fae7b2 100644 --- a/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php @@ -808,10 +808,6 @@ class ProjectAnalyzer ) { list($fq_class_name) = explode('::', $original_method_id); - $file_analyzer = $this->getFileAnalyzerForClassLike($fq_class_name); - - $file_analyzer->setRootFilePath($root_file_path, $root_file_name); - $appearing_method_id = $this->codebase->methods->getAppearingMethodId($original_method_id); if (!$appearing_method_id) { @@ -827,6 +823,10 @@ class ProjectAnalyzer return; } + $file_analyzer = $this->getFileAnalyzerForClassLike($fq_class_name); + + $file_analyzer->setRootFilePath($root_file_path, $root_file_name); + if (strtolower($appearing_fq_class_name) !== strtolower($fq_class_name)) { $file_analyzer = $this->getFileAnalyzerForClassLike($appearing_fq_class_name); } diff --git a/tests/PropertyTypeTest.php b/tests/PropertyTypeTest.php index 2c8275c47..7a91a551c 100644 --- a/tests/PropertyTypeTest.php +++ b/tests/PropertyTypeTest.php @@ -1547,6 +1547,20 @@ class PropertyTypeTest extends TestCase class Concrete extends Base {}' ], + 'preventCrashWhenCallingInternalMethodInPropertyInitialisationChecks' => [ + 'serializableTrace = $this->getTrace(); + } + } + + class Bar extends Foo {}', + ], ]; }