1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-21 21:31:13 +01:00

Fix #803 - trait methods are evaluated correctly now

This commit is contained in:
Matthew Brown 2018-06-08 20:06:05 -04:00
parent 29a971d40e
commit a2b1838e23
2 changed files with 25 additions and 24 deletions

View File

@ -358,26 +358,14 @@ class MethodCallChecker extends \Psalm\Checker\Statements\Expression\CallChecker
$classlike_source = $source_source->getSource();
$classlike_source_fqcln = $classlike_source ? $classlike_source->getFQCLN() : null;
if ($var_id === '$this' && $context->self && $classlike_source_fqcln) {
if ($fq_class_name !== $context->self
&& $codebase->methodExists($context->self . '::' . $method_name_lc)
) {
$method_id = $context->self . '::' . $method_name_lc;
$fq_class_name = $context->self;
} elseif ($classlike_source instanceof \Psalm\Checker\TraitChecker
&& $codebase->methodExists($classlike_source_fqcln . '::' . $method_name_lc)
) {
$declaring_method_id = (string) $codebase->methods->getDeclaringMethodId(
$classlike_source_fqcln . '::' . $method_name_lc
);
list($declaring_class) = explode('::', $declaring_method_id);
if ($declaring_class === $classlike_source_fqcln) {
$method_id = $classlike_source_fqcln . '::' . $method_name_lc;
$fq_class_name = $classlike_source_fqcln;
}
}
if ($var_id === '$this'
&& $context->self
&& $classlike_source_fqcln
&& $fq_class_name !== $context->self
&& $codebase->methodExists($context->self . '::' . $method_name_lc)
) {
$method_id = $context->self . '::' . $method_name_lc;
$fq_class_name = $context->self;
}
if ($intersection_types && !$codebase->methodExists($method_id)) {

View File

@ -475,10 +475,6 @@ class TraitTest extends TestCase
'aliasedMethodInternalCallWithLocalDefinition' => [
'<?php
trait T {
public function foo() : int {
return $this->bar();
}
public function bar() : int {
return 3;
}
@ -712,6 +708,23 @@ class TraitTest extends TestCase
}',
'error_message' => 'InvalidReturnType',
],
'replaceTraitMethod' => [
'<?php
trait T {
protected function foo() : void {}
public function bat() : void {
$this->foo();
}
}
class C {
use T;
protected function foo(string $s) : void {}
}',
'error_message' => 'TooFewArguments',
],
];
}
}