Iterated value is assumed to be always nullable if implementation of Iterator::current() allows null return value #9698
Open
Description
https://psalm.dev/r/d81595727c
It is possible to add @psalm-assert-if-true
/ @psalm-assert-if-false
to valid()
implementation and this helps with explicit current()
call.
However, when using the iterator in foreach
loop, psalm ignores both the @implements
annotation which states that iterated value is not nullable and the annotations on valid()
method which obviously returns true
inside foreach
.
Is it by design? Are there means to specify that iterated value is not nullable on Iterator implementation?