Skip to content

Union of literal types is generalized #28

@tpetry

Description

@tpetry

The following code should produce the type 'a' | 'b' | 'c' and not generalize the value to string:

use Psl\Type;
use function PHPStan\dumpType;

$literals = Type\union(
    Type\literal_scalar('a'),
    Type\literal_scalar('b'),
    Type\literal_scalar('c'),
);

$validated = $literals->coerce('a');
dumpType($validated); // Dumped type: string

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions