Skip to content

Generator: TSend other than mixed not supported #2987

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

Closed
caugner opened this issue Mar 18, 2020 · 1 comment
Closed

Generator: TSend other than mixed not supported #2987

caugner opened this issue Mar 18, 2020 · 1 comment

Comments

@caugner
Copy link
Contributor

caugner commented Mar 18, 2020

In the context of #2984, I noticed that a different value for Generators third type parameter (TSend) does not seem to support a value other than the default (mixed):
https://psalm.dev/r/b6bedecbb9

It causes the following error:

INFO: MixedReturnTypeCoercion - 5:12 - The declared return type 'Generator<int, int, int, void>' for generate is more specific than the inferred return type 'Generator<int, int, mixed, void>'

@andrew-demb pointed out the relevant stub code:

/**
* @template-covariant TKey
* @template-covariant TValue
* @template TSend
* @template-covariant TReturn
*
* @template-implements Traversable<TKey, TValue>
*/
class Generator implements Traversable {

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/b6bedecbb9
<?php

/**
 * @var int $int
 * @return Generator<int, int, int, void>
 */
function generate(int $int) {
    while (true) {
        $int = yield (2 * $int);
    }
}
Psalm output (using commit 474b9dc):

INFO: MixedReturnTypeCoercion - 5:12 - The declared return type 'Generator<int, int, int, void>' for generate is more specific than the inferred return type 'Generator<int, int, mixed, void>'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant