Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'' check is loosing literal-string type #10910

Open
VincentLanglet opened this issue Apr 17, 2024 · 1 comment
Open

'' check is loosing literal-string type #10910

VincentLanglet opened this issue Apr 17, 2024 · 1 comment

Comments

@VincentLanglet
Copy link
Contributor

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

Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant