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:
parent
29a971d40e
commit
a2b1838e23
@ -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)) {
|
||||
|
@ -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',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user