vimeo/psalm

Logic operations not parsed correctly in combination with class_exists

开放

#6,530 创建于 2021年9月24日

 (4 条评论) (0 个反应) (0 位负责人)PHP (668 个派生)batch import
Help wantedbug

仓库指标

星标
 (5,369 个星标)
PR 合并指标
 (PR 指标待抓取)

描述

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

贡献者指南