psalm icon indicating copy to clipboard operation
psalm copied to clipboard

Literal string considered `!string` by `is_string()`

Open SCIF opened this issue 1 year ago • 4 comments

https://psalm.dev/r/a232dce215

SCIF avatar Jul 23 '24 11:07 SCIF

I found these snippets:

https://psalm.dev/r/a232dce215
<?php

$a = 'some';

if (!is_string($a)) {
    throw new \Exception();
}
Psalm output (using commit 16b24bd):

ERROR: TypeDoesNotContainType - 5:6 - Type 'some' for $a is always !string

psalm-github-bot[bot] avatar Jul 23 '24 11:07 psalm-github-bot[bot]

I think the program is telling you that in your example $a is always a string, so your if test does make sense (i.e. you're testing for something that is unequivocally known to be true).

flaviovs avatar Jul 26 '24 04:07 flaviovs

I think the program is telling you that in your example $a is always a string, so your if test does make sense (i.e. you're testing for something that is unequivocally known to be true).

Sorry, but text says exatly opposite !string, which means it's not a string. I worry there could be a real bug rather than just error message typo.

SCIF avatar Jul 26 '24 04:07 SCIF

Hm, I can see even the codebase contains the suppession of this type of errors: https://github.com/vimeo/psalm/blob/5.x/src/Psalm/Internal/Provider/FileStorageCacheProvider.php#L92

Is this known behavior or just a bug which was suppresed for a long time??

SCIF avatar Jul 26 '24 04:07 SCIF