1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Fix possibly-private error

This commit is contained in:
Matthew Brown 2017-04-15 21:10:49 -04:00
parent f67e92023b
commit 007442fdd0
2 changed files with 35 additions and 0 deletions

View File

@ -791,6 +791,15 @@ class CallChecker
$method_id = $fq_class_name . '::' . strtolower($stmt->name);
if ($var_id === '$this' &&
$context->self &&
$fq_class_name !== $context->self &&
MethodChecker::methodExists($context->self . '::' . strtolower($stmt->name), $file_checker)
) {
$method_id = $context->self . '::' . strtolower($stmt->name);
$fq_class_name = $context->self;
}
if ($intersection_types && !MethodChecker::methodExists($method_id, $file_checker)) {
foreach ($intersection_types as $intersection_type) {
$method_id = $intersection_type->value . '::' . strtolower($stmt->name);

View File

@ -428,4 +428,30 @@ class ClassScopeTest extends PHPUnit_Framework_TestCase
$file_checker = new FileChecker('somefile.php', $this->project_checker, $stmts);
$file_checker->visitAndAnalyzeMethods();
}
/**
* @return void
*/
public function testDefinedPrivateMethod()
{
$stmts = self::$parser->parse('<?php
class A {
public function foo() : void {
if ($this instanceof B) {
$this->boop();
}
}
private function boop() : void {}
}
class B extends A {
private function boop() : void {}
}
');
$file_checker = new FileChecker('somefile.php', $this->project_checker, $stmts);
$context = new Context();
$file_checker->visitAndAnalyzeMethods($context);
}
}