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
"The call to ::getIterator is not used" reported right where it's used #3625
Comments
Hey @orklah, can you reproduce the issue on https://psalm.dev ? |
|
Reproduced with https://psalm.dev/r/6287fdb60c |
I found these snippets: https://psalm.dev/r/6287fdb60c<?php
/** @psalm-immutable */
class C implements IteratorAggregate {
public function getIterator(): Iterator {
return new ArrayIterator([]);
}
}
$d = [];
/** @psalm-suppress MixedAssignment */
foreach (new C as $elt) {
$d[(string)$elt] = $elt;
}
|
Kinda, but there isn't a psalm-immutable annotation in my case. And without it I can't reproduce the issue at all... |
Here are my reproducers from #4373 - slightly cleaner as they don't have other problems: https://psalm.dev/r/dd77299d18 |
I found these snippets: https://psalm.dev/r/dd77299d18<?php
/**
* @psalm-immutable
*/
class A implements IteratorAggregate
{
/**
* @return Iterator<string>
*/
public function getIterator() {
yield from [];
}
}
$a = new A;
foreach ($a as $v) {
echo $v;
}
https://psalm.dev/r/ab4bb38b1e<?php
class A implements IteratorAggregate
{
/**
* @return Iterator<string>
* @psalm-mutation-free
*/
public function getIterator() {
yield from [];
}
}
$a = new A;
foreach ($a as $v) {
echo $v;
}
|
Thanks @enumag! |
Hi,
We got a strange error on phpDocumentor CI:
https://github.com/phpDocumentor/phpDocumentor/runs/790360908?check_suite_focus=true#step:9:18
The error warn of an issue with a getIterator function being unused here:
phpDocumentor/phpDocumentor@337b40d#annotation_257518989
But that's exactly the line where it's actually used, I don't understand what psalm is trying to report here.
I couldn't reproduce the issue locally, but phpDocumentor CI is complex so I don't have the same setup.
The issue was "solved" by changing "findUnusedVariablesAndParams" to false, but it'd be cool to be able to enable this check again.
Do you have an idea what could be the issue here?
The text was updated successfully, but these errors were encountered: