mirror of
https://github.com/danog/psalm.git
synced 2024-11-26 20:34:47 +01:00
Fix #1427 - allow extended methods to be used as callables
This commit is contained in:
parent
bd372e93af
commit
cece1def30
@ -1027,6 +1027,12 @@ class TypeAnalyzer
|
||||
}
|
||||
|
||||
try {
|
||||
$method_id = $codebase->methods->getDeclaringMethodId($method_id);
|
||||
|
||||
if (!$method_id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$codebase->methods->getStorage($method_id);
|
||||
} catch (\Exception $e) {
|
||||
return false;
|
||||
|
@ -757,6 +757,30 @@ class CallableTest extends TestCase
|
||||
}
|
||||
}'
|
||||
],
|
||||
'publicCallableFromInside' => [
|
||||
'<?php
|
||||
class Base {
|
||||
public function publicMethod() : void {}
|
||||
}
|
||||
|
||||
class Example extends Base {
|
||||
public function test() : Closure {
|
||||
return Closure::fromCallable([$this, "publicMethod"]);
|
||||
}
|
||||
}',
|
||||
],
|
||||
'protectedCallableFromInside' => [
|
||||
'<?php
|
||||
class Base {
|
||||
protected function protectedMethod() : void {}
|
||||
}
|
||||
|
||||
class Example extends Base {
|
||||
public function test() : Closure {
|
||||
return Closure::fromCallable([$this, "protectedMethod"]);
|
||||
}
|
||||
}',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
@ -1234,6 +1258,19 @@ class CallableTest extends TestCase
|
||||
array_map(["two", "three"], ["one", "two"]);',
|
||||
'error_message' => 'InvalidArgument'
|
||||
],
|
||||
'privateCallable' => [
|
||||
'<?php
|
||||
class Base {
|
||||
private function privateMethod() : void {}
|
||||
}
|
||||
|
||||
class Example extends Base {
|
||||
public function test() : Closure {
|
||||
return Closure::fromCallable([$this, "privateMethod"]);
|
||||
}
|
||||
}',
|
||||
'InvalidArgument',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user