Skip to content
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

Callable infer and return type broken in master #4545

Closed
thomasvargiu opened this issue Nov 13, 2020 · 1 comment
Closed

Callable infer and return type broken in master #4545

thomasvargiu opened this issue Nov 13, 2020 · 1 comment
Labels

Comments

@thomasvargiu
Copy link
Contributor

Commit 3dd185e broke this:

https://psalm.dev/r/7f738e489c

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/7f738e489c
<?php
/**
 * @template T
 */
interface Functor
{
    /**
     * @template F
     * @param callable(T): F $function
     * @return Functor<F>
     */
    public function map(callable $function): Functor;
}

/**
 * @template T
 * @template-implements Functor<T>
 */
class FakeFunctor implements Functor
{
    /**
     * @var T
     */
    private $value;
    /**
     * @psalm-param T $value
     */
    public function __construct($value)
    {
        $this->value = $value;
    }

    public function map(callable $function): Functor
    {
        return new FakeFunctor($function($this->value));
    }
}

$foo = new FakeFunctor('foo');
$function = function (string $a): int {
    return strlen($a);
};
/** @psalm-trace $value */
$value = $foo->map($function); // this should be Functor<int>
Psalm output (using commit 5a62dc5):

INFO: Trace - 44:1 - $value: Functor

INFO: UnusedVariable - 44:1 - Variable $value is never referenced

@muglug muglug added the bug label Nov 13, 2020
@muglug muglug closed this as completed in 13b83e6 Nov 13, 2020
danog pushed a commit to danog/psalm that referenced this issue Jan 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants