Skip to content

Union of literal types is generalized #28

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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