psalm icon indicating copy to clipboard operation
psalm copied to clipboard

Disambiguate between class-string and interface-string?

Open ciaranmcnulty opened this issue 1 year ago • 1 comments

https://psalm.dev/r/73c14dc055

In both of these cases I'd expect one branch of the condition to have a class-string and the other to have an interface-string?

I'm additionally surprised to see class-string|string is not collapsed to string

ciaranmcnulty avatar Feb 05 '24 13:02 ciaranmcnulty

I found these snippets:

https://psalm.dev/r/73c14dc055
<?php

/** @var class-string|interface-string $type1 */
if (interface_exists($type1)) {
    /** @psalm-trace $type1 */
} else {
    /** @psalm-trace $type1 */
}

/** @var class-string|interface-string $type2 */
if (class_exists($type2)) {
    /** @psalm-trace $type2 */
} else {
    /** @psalm-trace $type2 */
}
Psalm output (using commit 4b2c698):

INFO: Trace - 5:0 - $type1: interface-string

INFO: Trace - 7:0 - $type1: class-string|string

INFO: Trace - 12:0 - $type2: class-string

INFO: Trace - 14:0 - $type2: string

psalm-github-bot[bot] avatar Feb 05 '24 13:02 psalm-github-bot[bot]