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
Psalm doesn't accept generic invokable class as callable #4550
Labels
Comments
I found these snippets: https://psalm.dev/r/6df07c8d07<?php
class OrderId
{
public string $value;
public function __construct(string $value)
{
$this->value = $value;
}
}
/**
* @template A
* @template B
*/
class _Callable
{
/** @var callable(A): B */
private $fn;
/**
* @param callable(A): B $fn
*/
public function __construct(callable $fn)
{
$this->fn = $fn;
}
/**
* @param A $a
* @return B
*/
public function __invoke($a)
{
return ($this->fn)($a);
}
/**
* @return callable(A): B
*/
public function unwrap(): callable
{
return $this->fn;
}
}
/**
* @param callable(string): OrderId $_
*/
function testCallable(callable $_): void
{
}
testCallable(
fn(string $value) => new OrderId($value)
);
testCallable((
new _Callable(fn(string $value) => new OrderId($value))
)->unwrap());
testCallable(
new _Callable(fn(string $value) => new OrderId($value))
);
|
klimick
changed the title
Psalm doesn't take generic invokable class as callable
Psalm doesn't accept generic invokable class as callable
Nov 14, 2020
Even with functions: https://psalm.dev/r/a51288e0e0 |
I found these snippets: https://psalm.dev/r/a51288e0e0<?php
/**
* @template B
*/
class A {
/** @var B */
private $value;
/** @param B $value */
public function __construct($value) {
$this->value = $value;
}
/** @return B */
public function __invoke()
{
return $this->value;
}
}
$a = new A('foo');
/** @psalm-trace $v */
$v = Closure::fromCallable($a);
/** @psalm-trace $r */
$r = $v();
|
Fixed in #7417 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bug or type inference limitation?
https://psalm.dev/r/6df07c8d07
The text was updated successfully, but these errors were encountered: