-
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
Bug with partially templated callable? #4531
Comments
I found these snippets: https://psalm.dev/r/ec02d9ad54<?php
/**
* @template TP
* @template TR
* @psalm-param callable(TP): TR $func
* @psalm-return callable(TP): TP
*/
function tee(callable $func): callable {
return function ($a) use ($func) {
$func($a);
return $a;
};
}
/**
* @template TP
* @psalm-param callable(TP): mixed $func
* @psalm-return callable(TP): TP
*/
function tee2(callable $func): callable {
return function ($a) use ($func) {
$func($a);
return $a;
};
}
/** @psalm-trace $f */
$f = tee(fn (int $a): string => $a . 'foo');
/** @psalm-trace $f */
$f = tee2(fn (int $a): string => $a . 'foo');
|
thomasvargiu
changed the title
Bug with partially templated callable
Bug with partially templated callable?
Nov 11, 2020
There's no feasible way for Psalm to infer this type correctly, so it chooses the empty type (similar to a bottom type). |
Correction: there is a way, and now it does. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Related to #4485
There is a problem when I don't explicity set a template for a callable return type.
https://psalm.dev/r/ec02d9ad54
If I ignore the return type template for the callable input, even if I'm not using it, checks fail.
If I put a template, it works as expected.
In this case I don't care about callable return type, so I shouldn't need to specify a template.
The text was updated successfully, but these errors were encountered: