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

UnusedMethodCall false positive with foreach #4373

Closed
enumag opened this issue Oct 20, 2020 · 5 comments
Closed

UnusedMethodCall false positive with foreach #4373

enumag opened this issue Oct 20, 2020 · 5 comments

Comments

@enumag
Copy link
Contributor

enumag commented Oct 20, 2020

https://psalm.dev/r/dd77299d18

@psalm-github-bot
Copy link

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;
}
Psalm output (using commit b904b1d):

ERROR: UnusedMethodCall - 18:10 - The call to A::getIterator is not used

@orklah
Copy link
Collaborator

orklah commented Oct 20, 2020

Seems similar to: #3625

EDIT: except it didn't have an immutable annotation

@enumag
Copy link
Contributor Author

enumag commented Oct 20, 2020

Yeah it's the same problem. My snippet is just a bit cleaner since it doesn't have other issues.

Immutable annotation is not completely necessary. For instance @psalm-mutation-free has the same effect.

https://psalm.dev/r/ab4bb38b1e

@psalm-github-bot
Copy link

I found these snippets:

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;
}
Psalm output (using commit b904b1d):

ERROR: UnusedMethodCall - 16:10 - The call to A::getIterator is not used

@enumag
Copy link
Contributor Author

enumag commented Oct 20, 2020

Closing as duplicate of #3625

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

2 participants