Skip to content

Type\converted() leads to insufficient type inference on shape types #35

Description

@Ocramius

When using Psl\Type\converted(), PHPStan fails to infer the type of produced shapes:

/**
 * @return \Psl\Type\TypeInterface<array{foo: non-empty-string}>
 */
function test() {
    return \Psl\Type\converted(
        \Psl\Type\shape([
            'foo' => \Psl\Type\int(),
        ]),
        \Psl\Type\shape([
            'foo' => \Psl\Type\non_empty_string(),
        ]),
        static function (array $in): array {
            return [
                'foo' => (string) $in['foo']
            ];
        }
    );
}

This could well be a PHPStan limitation, given that Psl\Type\Converted has the output type bound to both the target type and the closure, and PHPStan does not parse any /** @return ... */ declarations on closures.

/cc @ondrejmirtes this is probably related to PHPStan not parsing docblocks on closures

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