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
psalm-pure invalid error #8625
Comments
I found these snippets: https://psalm.dev/r/dff3f37215<?php
/**
* @psalm-pure
*
* @return Hello
*/
function abc() {
$xyz = new Hello();
$xyz->world = true;
return $xyz;
}
class Hello {
public bool $world = false;
}
|
It is the With no additional annotation, this could happen: So Psalm must forbid you to modify attributes when precautions are not taken. However, you could use Psalm will then allow you to change this attribute |
I found these snippets: https://psalm.dev/r/413d60d78e<?php
/**
* @psalm-pure
*
* @return Hello
*/
function abc() {
$xyz = new Hello();
$xyz->world = true;
return $xyz;
}
class Hello {
public function __set($param, $value){
echo "This is a major side effect!";
}
}
https://psalm.dev/r/97334d3fc9<?php
/**
* @psalm-pure
*
* @return Hello
*/
function abc() {
$xyz = new Hello();
$xyz->world = true;
return $xyz;
}
/** @psalm-external-mutation-free */
class Hello {
public bool $world = false;
}
|
But I do not have a |
Your object is not final, so __set could still be defined in a child that would not be known by Psalm (but it seems like even with final, Psalm doesn't allow it) I guess we could add handling for setting a property on an object if:
I think I covered every possibility! Or you could flag the object external-mutation-free and help Psalm a little 😄 |
The problem is with #8624 - bc of this false positive, how do you suggest to handle this never type? (without completely reworking the type combiner, which eats the never type, making this property necessary in the first place) |
Do you have a snippet to show how this is related to never? I really struggle to grasp what's bugging you here |
Issue solved itself as the underlying stuff in psalm was changed/fixed |
https://psalm.dev/docs/annotating_code/supported_annotations/#:~:text=one%20whose%20output%20is%20just%20a%20function%20of%20its%20input
https://psalm.dev/r/dff3f37215 the output of
abc()
is pure, as it only depends on the input given (= always returns the same output for same input and has no side-effects) - but it still reports an error for it?Are the docs wrong/am I misunderstanding "purity"? Or is this a bug?
The text was updated successfully, but these errors were encountered: