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

Should Countable::count() be mutation-free? #4396

Closed
enumag opened this issue Oct 22, 2020 · 3 comments
Closed

Should Countable::count() be mutation-free? #4396

enumag opened this issue Oct 22, 2020 · 3 comments

Comments

@enumag
Copy link
Contributor

enumag commented Oct 22, 2020

https://psalm.dev/r/feb35a0874

I'm kinda considering this a bug. Imo count should never change anything inside the data structure. But maybe it's like this on purpose for some reason I can't see?

@psalm-github-bot
Copy link

I found these snippets:

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

/**
 * @psalm-immutable
 */
class A {
	public function test(Countable $x): void {
    	$x->count();
    }
}
Psalm output (using commit ad5a8c2):

ERROR: ImpureMethodCall - 8:10 - Cannot call an possibly-mutating method Countable::count from a mutation-free context

@jsiefer
Copy link

jsiefer commented Oct 22, 2020

Since the implementation of a countable could implement anything, psalm is reporting correctly.

@muglug
Copy link
Collaborator

muglug commented Oct 22, 2020

Yup, not a bug

@muglug muglug closed this as completed Oct 22, 2020
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

3 participants