psalm
psalm copied to clipboard
`''` check is loosing literal-string type
When doing an early return on '' === $string
the literal-string type is lost.
Notice that the early return on !$string
doesn't produce the same issue.
https://psalm.dev/r/6e2018c6b3
I found these snippets:
https://psalm.dev/r/6e2018c6b3
<?php
/**
* @param literal-string $s
*/
function foo1(string $s): void
{
if ('' === $s) {
return;
}
/** @psalm-trace $b */
$b = $s;
}
/**
* @param literal-string $s
*/
function foo2(string $s): void
{
if (!$s) {
return;
}
/** @psalm-trace $b */
$b = $s;
}
Psalm output (using commit 08afc45):
INFO: Trace - 13:5 - $b: non-empty-string
INFO: UnusedVariable - 13:5 - $b is never referenced or the value is not used
INFO: Trace - 26:5 - $b: non-empty-literal-string
INFO: UnusedVariable - 26:5 - $b is never referenced or the value is not used