From 031c5be8e6973f24fbbbb1db0b706fa4ba5bf58e Mon Sep 17 00:00:00 2001 From: Brown Date: Fri, 27 Mar 2020 00:37:33 -0400 Subject: [PATCH] Check trait methods better --- src/Psalm/Internal/Analyzer/ClassAnalyzer.php | 8 ---- tests/FileUpdates/AnalyzedMethodTest.php | 33 +++++++++++---- tests/FileUpdates/TemporaryUpdateTest.php | 41 +++++++++++++++++++ 3 files changed, 65 insertions(+), 17 deletions(-) diff --git a/src/Psalm/Internal/Analyzer/ClassAnalyzer.php b/src/Psalm/Internal/Analyzer/ClassAnalyzer.php index 5b1a592e9f1..d21bd78ade1 100644 --- a/src/Psalm/Internal/Analyzer/ClassAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/ClassAnalyzer.php @@ -1117,10 +1117,6 @@ private function checkPropertyInitialization( $included_file_path = $this->getFilePath(); - if ($class_context->include_location) { - $included_file_path = $class_context->include_location->file_path; - } - $method_already_analyzed = $codebase->analyzer->isMethodAlreadyAnalyzed( $included_file_path, $fq_class_name_lc . '::__construct', @@ -1641,10 +1637,6 @@ private function analyzeClassMethod( $included_file_path = $source->getFilePath(); - if ($class_context->include_location) { - $included_file_path = $class_context->include_location->file_path; - } - if ($class_context->self && strtolower($class_context->self) !== strtolower((string) $source->getFQCLN())) { $analyzed_method_id = $method_analyzer->getMethodId($class_context->self); diff --git a/tests/FileUpdates/AnalyzedMethodTest.php b/tests/FileUpdates/AnalyzedMethodTest.php index e480bc702b8..2efb24638d5 100644 --- a/tests/FileUpdates/AnalyzedMethodTest.php +++ b/tests/FileUpdates/AnalyzedMethodTest.php @@ -476,8 +476,10 @@ public function barBar(): string { }', ], 'initial_analyzed_methods' => [ - getcwd() . DIRECTORY_SEPARATOR . 'A.php' => [ + getcwd() . DIRECTORY_SEPARATOR . 'T.php' => [ 'foo\a::barbar&foo\t::barbar' => 1, + ], + getcwd() . DIRECTORY_SEPARATOR . 'A.php' => [ 'foo\a::foofoo' => 1, ], getcwd() . DIRECTORY_SEPARATOR . 'B.php' => [ @@ -487,9 +489,10 @@ public function barBar(): string { ], ], 'unaffected_analyzed_methods' => [ - getcwd() . DIRECTORY_SEPARATOR . 'A.php' => [ + getcwd() . DIRECTORY_SEPARATOR . 'T.php' => [ 'foo\a::barbar&foo\t::barbar' => 1, ], + getcwd() . DIRECTORY_SEPARATOR . 'A.php' => [], getcwd() . DIRECTORY_SEPARATOR . 'B.php' => [ 'foo\b::bar' => 1, 'foo\b::noreturntype' => 1, @@ -559,8 +562,10 @@ public function barBar(): string { }', ], 'initial_analyzed_methods' => [ - getcwd() . DIRECTORY_SEPARATOR . 'A.php' => [ + getcwd() . DIRECTORY_SEPARATOR . 'T.php' => [ 'foo\a::barbar&foo\t::barbar' => 1, + ], + getcwd() . DIRECTORY_SEPARATOR . 'A.php' => [ 'foo\a::foofoo' => 1, ], getcwd() . DIRECTORY_SEPARATOR . 'B.php' => [ @@ -569,6 +574,7 @@ public function barBar(): string { ], ], 'unaffected_analyzed_methods' => [ + getcwd() . DIRECTORY_SEPARATOR . 'T.php' => [], getcwd() . DIRECTORY_SEPARATOR . 'A.php' => [], getcwd() . DIRECTORY_SEPARATOR . 'B.php' => [], ], @@ -637,8 +643,10 @@ public function barBar(): string { }', ], 'initial_analyzed_methods' => [ - getcwd() . DIRECTORY_SEPARATOR . 'A.php' => [ + getcwd() . DIRECTORY_SEPARATOR . 'T.php' => [ 'foo\a::barbar&foo\t::barbar' => 1, + ], + getcwd() . DIRECTORY_SEPARATOR . 'A.php' => [ 'foo\a::foofoo' => 1, ], getcwd() . DIRECTORY_SEPARATOR . 'B.php' => [ @@ -647,6 +655,7 @@ public function barBar(): string { ], ], 'unaffected_analyzed_methods' => [ + getcwd() . DIRECTORY_SEPARATOR . 'T.php' => [], getcwd() . DIRECTORY_SEPARATOR . 'A.php' => [], getcwd() . DIRECTORY_SEPARATOR . 'B.php' => [], ], @@ -721,9 +730,11 @@ public function bat(): string { }', ], 'initial_analyzed_methods' => [ - getcwd() . DIRECTORY_SEPARATOR . 'A.php' => [ + getcwd() . DIRECTORY_SEPARATOR . 'T.php' => [ 'foo\a::barbar&foo\t::barbar' => 1, 'foo\a::bat&foo\t::bat' => 1, + ], + getcwd() . DIRECTORY_SEPARATOR . 'A.php' => [ 'foo\a::foofoo' => 1, ], getcwd() . DIRECTORY_SEPARATOR . 'B.php' => [ @@ -732,9 +743,10 @@ public function bat(): string { ], ], 'unaffected_analyzed_methods' => [ - getcwd() . DIRECTORY_SEPARATOR . 'A.php' => [ + getcwd() . DIRECTORY_SEPARATOR . 'T.php' => [ 'foo\a::bat&foo\t::bat' => 1, ], + getcwd() . DIRECTORY_SEPARATOR . 'A.php' => [], getcwd() . DIRECTORY_SEPARATOR . 'B.php' => [], ], ], @@ -792,7 +804,7 @@ public function barBar(): string { }', ], 'initial_analyzed_methods' => [ - getcwd() . DIRECTORY_SEPARATOR . 'A.php' => [ + getcwd() . DIRECTORY_SEPARATOR . 'T.php' => [ 'foo\a::barbar&foo\t::barbar' => 1, ], getcwd() . DIRECTORY_SEPARATOR . 'B.php' => [ @@ -800,7 +812,7 @@ public function barBar(): string { ], ], 'unaffected_analyzed_methods' => [ - getcwd() . DIRECTORY_SEPARATOR . 'A.php' => [], + getcwd() . DIRECTORY_SEPARATOR . 'T.php' => [], getcwd() . DIRECTORY_SEPARATOR . 'B.php' => [], ], ], @@ -1108,12 +1120,15 @@ private function setFoo() : void { }', ], 'initial_analyzed_methods' => [ - getcwd() . DIRECTORY_SEPARATOR . 'A.php' => [ + getcwd() . DIRECTORY_SEPARATOR . 'T.php' => [ 'foo\a::setfoo&foo\t::setfoo' => 1, + ], + getcwd() . DIRECTORY_SEPARATOR . 'A.php' => [ 'foo\a::__construct' => 2, ], ], 'unaffected_analyzed_methods' => [ + getcwd() . DIRECTORY_SEPARATOR . 'T.php' => [], getcwd() . DIRECTORY_SEPARATOR . 'A.php' => [], ], ], diff --git a/tests/FileUpdates/TemporaryUpdateTest.php b/tests/FileUpdates/TemporaryUpdateTest.php index 30f943f13ad..d10fecb0ddd 100644 --- a/tests/FileUpdates/TemporaryUpdateTest.php +++ b/tests/FileUpdates/TemporaryUpdateTest.php @@ -1438,6 +1438,47 @@ public function b(): void ], 'error_positions' => [[], []], ], + 'dontForgetErrorInTraitMethod' => [ + [ + [ + getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'A.php' => 'foo();', + getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'T.php' => ' 'foo();', + getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'T.php' => ' [[192, 192], [192, 192]], + ], ]; } }