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

Built-in NoRewindIterator stub does not work #6387

Closed
vudaltsov opened this issue Sep 2, 2021 · 6 comments · Fixed by #6390
Closed

Built-in NoRewindIterator stub does not work #6387

vudaltsov opened this issue Sep 2, 2021 · 6 comments · Fixed by #6390
Labels

Comments

@vudaltsov
Copy link
Contributor

https://psalm.dev/r/a7edd80625

@psalm-github-bot
Copy link

I found these snippets:

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

/**
 * @return Generator<int, string>
 */
function generator(): Generator
{
    yield 'test';
}

$iterator = new NoRewindIterator(generator());

/** @psalm-trace $iterator */
Psalm output (using commit eb973ab):

INFO: Trace - 13:30 - $iterator: NoRewindIterator<mixed, mixed>

@orklah
Copy link
Collaborator

orklah commented Sep 2, 2021

It seems to work when we push an Iterator instead of a Generator: https://psalm.dev/r/b8a3eaff57

@psalm-github-bot
Copy link

I found these snippets:

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

/**
 * @return Iterator<int, string>
 */
function generator()
{
    
}

$iterator = new NoRewindIterator(generator());

/** @psalm-trace $iterator */
Psalm output (using commit eb973ab):

ERROR: InvalidReturnType - 4:12 - No return statements were found for method generator but return type 'Iterator<int, string>' was expected

INFO: Trace - 13:30 - $iterator: NoRewindIterator<int, string>

@orklah orklah added the bug label Sep 2, 2021
@orklah
Copy link
Collaborator

orklah commented Sep 2, 2021

The stub declare it accepts an Iterator so Generator should be accepted: https://3v4l.org/lqr5D

@weirdan
Copy link
Collaborator

weirdan commented Sep 2, 2021

Reproducible with user-defined classes as well: https://psalm.dev/r/36a0f142e0

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/36a0f142e0
<?php

/**
 * @template TK
 * @template TV
 */
class C {
    /**
     * @param Iterator<TK,TV> $it
     */    
    public function __construct($it) {}
}

/** @return Generator<int, string> */
function generator(): Generator {
    yield "a";
}

$_t = new C(generator());
/** @psalm-trace $_t */;
Psalm output (using commit eb973ab):

INFO: Trace - 20:24 - $_t: C<mixed, mixed>

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

Successfully merging a pull request may close this issue.

3 participants