-
Notifications
You must be signed in to change notification settings - Fork 653
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uncaught Exception: Could not locate trait statement #2951
Comments
Hey @kelunik, can you reproduce the issue on https://psalm.dev ? |
Not really, it says |
I found these snippets: https://psalm.dev/r/a6601ab157<?php
namespace Amp;
// @codeCoverageIgnoreStart
if (\PHP_VERSION_ID < 70100) {
trait CallableMaker
{
/** @var \ReflectionClass */
private static $__reflectionClass;
/** @var \ReflectionMethod[] */
private static $__reflectionMethods = [];
/**
* Creates a callable from a protected or private instance method that may be invoked by callers requiring a
* publicly invokable callback.
*
* @param string $method Instance method name.
*
* @return callable
*/
private function callableFromInstanceMethod(string $method): callable
{
if (!isset(self::$__reflectionMethods[$method])) {
if (self::$__reflectionClass === null) {
self::$__reflectionClass = new \ReflectionClass(self::class);
}
self::$__reflectionMethods[$method] = self::$__reflectionClass->getMethod($method);
}
return self::$__reflectionMethods[$method]->getClosure($this);
}
/**
* Creates a callable from a protected or private static method that may be invoked by methods requiring a
* publicly invokable callback.
*
* @param string $method Static method name.
*
* @return callable
*/
private static function callableFromStaticMethod(string $method): callable
{
if (!isset(self::$__reflectionMethods[$method])) {
if (self::$__reflectionClass === null) {
self::$__reflectionClass = new \ReflectionClass(self::class);
}
self::$__reflectionMethods[$method] = self::$__reflectionClass->getMethod($method);
}
return self::$__reflectionMethods[$method]->getClosure();
}
}
} else {
trait CallableMaker
{
/**
* @deprecated Use \Closure::fromCallable() instead of this method in PHP 7.1.
*/
private function callableFromInstanceMethod(string $method): callable
{
return \Closure::fromCallable([$this, $method]);
}
/**
* @deprecated Use \Closure::fromCallable() instead of this method in PHP 7.1.
*/
private static function callableFromStaticMethod(string $method): callable
{
return \Closure::fromCallable([self::class, $method]);
}
}
} // @codeCoverageIgnoreEnd
|
Similar bug reported on phpunit plugin: psalm/psalm-plugin-phpunit#56, also involving conditionally defined trait: https://github.com/symfony/symfony/blob/14b825b24fece6a4853d7bf537b86df88d3bfcc1/src/Symfony/Component/Validator/Test/ForwardCompatTestTrait.php |
I'll release a fix today for this that uses reflection to determine the winner when there's more than one trait defined in a given file. |
@muglug Thanks for the quick fix. Now I get the
|
Adding |
You can suppress that in your
|
Thanks! |
Running
--init
on Amp currently isn't possible. This is due to the conditional definition of ourCallableMaker
trait. Can I work around this or could Psalm be extended to evaluatePHP_VERSION_ID
and pick the right version?The text was updated successfully, but these errors were encountered: