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

Generic function returns generic Closure #10434

Closed
SyuTingSong opened this issue Jan 15, 2024 · 2 comments
Closed

Generic function returns generic Closure #10434

SyuTingSong opened this issue Jan 15, 2024 · 2 comments

Comments

@SyuTingSong
Copy link

Feature request

I create a function that returns a closure.

/**
 * @template TKey of array-key
 * @template RKey of array-key
 * @template TValue
 *
 * @param callable(TKey):RKey $fn
 *
 * @return Closure(iterable<TKey,TValue>):Generator<RKey,TValue>
 */
function map_keys(callable $fn): Closure
{
    return function(iterable $iterable) use ($fn): Generator {
        foreach($iterable as $key => $value) {
            $mapped_key = $fn($key);
            yield $mapped_key => $value;
        }
    };
}

Currently, the PHPStan reports an error:

Template type TValue of function map_keys() is not referenced in a parameter.

Open in playground.

I hope I can declare the TValue as a template of the returning closure, instead a template of the function map_keys.

Did PHPStan help you today? Did it make you happy in any way?

No response

@ondrejmirtes
Copy link
Member

Duplicate of #8964

@ondrejmirtes ondrejmirtes marked this as a duplicate of #8964 Feb 20, 2024
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants