vimeo/psalm

Logic operations not parsed correctly in combination with class_exists

Open

#6 530 ouverte le 24 sept. 2021

Voir sur GitHub
 (4 commentaires) (0 réactions) (0 assignés)PHP (668 forks)batch import
Help wantedbug

Métriques du dépôt

Stars
 (5 369 stars)
Métriques de merge PR
 (Merge moyen 3j 12h) (5 PRs mergées en 30 j)

Description

Not sure this issue has a wider impact, but this is how I found it.

Consider this snippet:

https://psalm.dev/r/6bc7fcec49

The issues reported for AnotherClass are false positives: it is impossible that the AnotherClass class is not defined due to the first if.

In fact, issues are correctly not reported for SomeClass.

If I split the logic operation in the first if and create two separate conditions everything works correctly:

https://psalm.dev/r/be71085536

So I think Psalm does not parse correctly logic operators with class_exists.

For additional context, see also:

https://psalm.dev/r/e8d3adb172

In there, the inner if would be executed only if both classes exist, so all the reported issues are false positives. And once again, with a single class everything works:

https://psalm.dev/r/0e43940c34

Guide contributeur