Skip to content

Fix union assertions#8324

Merged
orklah merged 13 commits intovimeo:masterfrom
nicelocal:fix_union_assertions
Jul 28, 2022
Merged

Fix union assertions#8324
orklah merged 13 commits intovimeo:masterfrom
nicelocal:fix_union_assertions

Conversation

@danog
Copy link
Copy Markdown
Collaborator

@danog danog commented Jul 27, 2022

Fixes #8322, #8319 and a few other bugs introduced by #8077, by explicitly running the intersection logic only on IsIdentical assertions (due to the semantics of Type::intersectUnionTypes wasn't sure if we should run it on IsType assertions), and removing the custom intersection/equality logic which broke other stuff in the code.

@danog
Copy link
Copy Markdown
Collaborator Author

danog commented Jul 27, 2022

The shepherd issue seems to be present upstream: https://psalm.dev/r/e0bee4534f

@psalm-github-bot
Copy link
Copy Markdown

I found these snippets:

https://psalm.dev/r/e0bee4534f
<?php
                    /**
                     * Asserts that two variables are the same.
                     *
                     * @param object $actual
                     * @psalm-assert-if-true (a|b|c) $actual
                     */
                    function assertSame($actual) : void {}
                    class a {}
                    class b {}
                    class c {}
/** @var object */
                    $actual = new c;
if (assertSame($actual)) {
/** @psalm-trace $actual */;
}
Psalm output (using commit 63b389f):

INFO: UnusedParam - 8:41 - Param $actual is never referenced in this method

INFO: Trace - 15:28 - $actual: a

Comment thread src/Psalm/Type.php
@danog
Copy link
Copy Markdown
Collaborator Author

danog commented Jul 27, 2022

Mm actually even with the additional int range handling in intersections we're still missing intersection logic for keyed arrays, I feel like I'm duplicating code already present in the assertion reconciler, once I fix the last unit case I'd still prefer to get this merged, but eventually we should be using the same code used in the assertion reconciler to perform intersections, differences&so on...

@danog
Copy link
Copy Markdown
Collaborator Author

danog commented Jul 28, 2022

All done!

@danog danog requested a review from orklah July 28, 2022 10:08
@orklah orklah added the release:fix The PR will be included in 'Fixes' section of the release notes label Jul 28, 2022
@orklah orklah merged commit 7c4228f into vimeo:master Jul 28, 2022
@orklah
Copy link
Copy Markdown
Collaborator

orklah commented Jul 28, 2022

Thanks!

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

Labels

release:fix The PR will be included in 'Fixes' section of the release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants