memoizeMethodCallResults: Why is the default false
?
#8964
-
Questions
Take a look at the examples below. The behavior seems incorrect by default, at least to me. I am trying to describe an assertion, but it does not work by default. BackgroundSee the examples here: Problem: psalm.dev/r/f5483fbbfa Only difference: The docs say:
psalm.dev/docs/annotating_code/adding_assertions/#asserting-return-values-of-methods Code HistoryIt looks like it was added it back in very early psalm (v1.1.5) and it was defaulted to false. Sadly, there is no description for why it is I suspect the goal for the maintainers is to respect sem-ver. Thus, |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
There are no guarantees that a method will return the same value every time, yet In this case, the right thing to do is annotate the method as mutation-free: https://psalm.dev/r/189bf1c362. This way Psalm will actually validate that the method does not change any state. |
Beta Was this translation helpful? Give feedback.
There are no guarantees that a method will return the same value every time, yet
memoizeMethodCallResults="true"
implies just that, for all methods. Therefore this setting is risky at best, and should not be enabled by default. Perhaps we should deprecate it and remove it in the next major version.In this case, the right thing to do is annotate the method as mutation-free: https://psalm.dev/r/189bf1c362. This way Psalm will actually validate that the method does not change any state.