Skip to content

literal strings as non-empty-string #5017

@thomasvargiu

Description

@thomasvargiu

Should literal strings be a non-empty-string?

The problem I occurred is the following:

/**
 * @return list<non-empty-string>
 */
function a(): array
{
    // Imaging I have an external declared type like this:
    /** @var array{foo?: list<non-empty-string>} $array */
    $array = [];

    return $array['foo'] ?? ['bar'];
}

https://psalm.dev/r/0cb0b9aa53

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions