Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect union assembled from imported typedef #3929

Closed
alexandrmazur96 opened this issue Aug 3, 2020 · 1 comment
Closed

Incorrect union assembled from imported typedef #3929

alexandrmazur96 opened this issue Aug 3, 2020 · 1 comment
Labels

Comments

@alexandrmazur96
Copy link

Here I would expect array{id: int, something?: int} but array{id: int, something: int} is inferred:
https://psalm.dev/r/86bee2c4c8

However, when types are declared directly on the using class union type is inferred as expected:
https://psalm.dev/r/7062f9c623

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/86bee2c4c8
<?php

namespace A\B;

/**
 * @psalm-type _A=array{
 *      id:int
 * }
 *
 * @psalm-type _B=array{
 *      id:int,
 *      something:int
 * }
 */
class Types
{
}

namespace A;

/**
 * @psalm-import-type _A from \A\B\Types
 * @psalm-import-type _B from \A\B\Types
 */
class Id
{
    /**
     * @psalm-param _A|_B $_item
     */
    public function ff(array $_item): void
    {
        /** @psalm-trace $_item */
    }
}
Psalm output (using commit 9dfdcbe):

INFO: Trace - 32:0 - $_item: array{id: int, something: int}
https://psalm.dev/r/7062f9c623
<?php

/**
 * @psalm-type _A=array{
 *      id:int
 * }
 *
 * @psalm-type _B=array{
 *      id:int,
 *      something:int
 * }
 */
class Id
{
    /**
     * @psalm-param _A|_B $_item
     */
    public function ff(array $_item): void
    {
        /** @psalm-trace $_item */
    }
}
Psalm output (using commit 9dfdcbe):

INFO: Trace - 20:0 - $_item: array{id: int, something?: int}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants