Skip to content

Iterated value is assumed to be always nullable if implementation of Iterator::current() allows null return value #9698

Open
@sad-spirit

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?

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions