Skip to content

Commit

Permalink
Check trait methods better
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Mar 27, 2020
1 parent 53612d0 commit 031c5be
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 17 deletions.
8 changes: 0 additions & 8 deletions src/Psalm/Internal/Analyzer/ClassAnalyzer.php
Expand Up @@ -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',
Expand Down Expand Up @@ -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);

Expand Down
33 changes: 24 additions & 9 deletions tests/FileUpdates/AnalyzedMethodTest.php
Expand Up @@ -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' => [
Expand All @@ -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,
Expand Down Expand Up @@ -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' => [
Expand All @@ -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' => [],
],
Expand Down Expand Up @@ -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' => [
Expand All @@ -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' => [],
],
Expand Down Expand Up @@ -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' => [
Expand All @@ -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' => [],
],
],
Expand Down Expand Up @@ -792,15 +804,15 @@ 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' => [
'foo\b::bar' => 1,
],
],
'unaffected_analyzed_methods' => [
getcwd() . DIRECTORY_SEPARATOR . 'A.php' => [],
getcwd() . DIRECTORY_SEPARATOR . 'T.php' => [],
getcwd() . DIRECTORY_SEPARATOR . 'B.php' => [],
],
],
Expand Down Expand Up @@ -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' => [],
],
],
Expand Down
41 changes: 41 additions & 0 deletions tests/FileUpdates/TemporaryUpdateTest.php
Expand Up @@ -1438,6 +1438,47 @@ public function b(): void
],
'error_positions' => [[], []],
],
'dontForgetErrorInTraitMethod' => [
[
[
getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'A.php' => '<?php
namespace Foo;
class A {
use T;
}
(new A)->foo();',
getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'T.php' => '<?php
namespace Foo;
trait T {
public function foo() : void {
echo $a;
}
}',
],
[
getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'A.php' => '<?php
namespace Foo;
class A {
use T;
}
(new A)->foo();',
getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'T.php' => '<?php
namespace Foo;
trait T {
public function foo() : void {
echo $a;
}
}',
],
],
'error_positions' => [[192, 192], [192, 192]],
],
];
}
}

0 comments on commit 031c5be

Please sign in to comment.