Skip to content

False positive NoValue  #9349

@mrsuh

Description

@mrsuh

Hi.
Psalm 5.7.1
I got this error on a simple example.

<?php

$str = $argv[1] ?? '';
if(empty($str) || strlen($str) < 3) {
    exit(1);
}

echo $str; // ERROR: [NoValue](https://psalm.dev/179) - 8:6 - All possible types for this argument were invalidated - This may be dead code

https://psalm.dev/r/f12fbc1db8

The error disappeared when I removed the unnecessary "empty" check.

<?php

$str = $argv[1] ?? '';
if(strlen($str) < 3) {
    exit(1);
}

echo $str;

https://psalm.dev/r/a0bf807db5

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions