-
Notifications
You must be signed in to change notification settings - Fork 575
Do not normalize union types in tryRemove to preserve finite type combinations #5744
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
Open
phpstan-bot
wants to merge
6
commits into
phpstan:2.1.x
Choose a base branch
from
phpstan-bot:create-pull-request/patch-6m54aw0
base: 2.1.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d568432
Do not normalize union types in tryRemove to preserve finite type com…
VincentLanglet 9e71d14
Move BenevolentUnionType tryRemove handling to override and remove de…
phpstan-bot 3afa55f
Add non-regression test for match exhaustiveness with arrays of union…
phpstan-bot 0a839cc
simplify diff
staabm 353afca
cheap first
staabm ccb46d1
Revert "cheap first"
staabm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| <?php // lint >= 8.1 | ||
|
|
||
| declare(strict_types = 1); | ||
|
|
||
| namespace Bug10128; | ||
|
|
||
| enum FooBar { | ||
| case Bar; | ||
| case Baz; | ||
| case Foo; | ||
| } | ||
|
|
||
| function getFoo(): FooBar { | ||
| return FooBar::Bar; | ||
| } | ||
|
|
||
| function test(): void { | ||
| $first = getFoo(); | ||
| $second = getFoo(); | ||
|
|
||
| $type = match ([$first, $second]) { | ||
| [FooBar::Bar, FooBar::Bar] => 1, | ||
| [FooBar::Bar, FooBar::Baz] => 2, | ||
| [FooBar::Bar, FooBar::Foo] => 3, | ||
|
|
||
| [FooBar::Baz, FooBar::Bar] => 1, | ||
| [FooBar::Baz, FooBar::Baz] => 2, | ||
| [FooBar::Baz, FooBar::Foo] => 3, | ||
|
|
||
| [FooBar::Foo, FooBar::Bar] => 1, | ||
| [FooBar::Foo, FooBar::Baz] => 2, | ||
| [FooBar::Foo, FooBar::Foo] => 3, | ||
| }; | ||
|
|
||
| $type2 = match ([$first, $second]) { | ||
| [FooBar::Bar, FooBar::Bar], | ||
| [FooBar::Bar, FooBar::Baz], | ||
| [FooBar::Bar, FooBar::Foo] => 1, | ||
|
|
||
| [FooBar::Baz, FooBar::Bar] => 1, | ||
| [FooBar::Baz, FooBar::Baz] => 2, | ||
| [FooBar::Baz, FooBar::Foo] => 3, | ||
|
|
||
| [FooBar::Foo, FooBar::Bar] => 1, | ||
| [FooBar::Foo, FooBar::Baz] => 2, | ||
| [FooBar::Foo, FooBar::Foo] => 3, | ||
| }; | ||
|
|
||
| $type3 = match ([$first, $second]) { | ||
| [FooBar::Bar, FooBar::Bar], | ||
| [FooBar::Baz, FooBar::Baz], | ||
| [FooBar::Foo, FooBar::Foo], | ||
| [FooBar::Foo, FooBar::Baz] => 1, | ||
|
|
||
| [FooBar::Bar, FooBar::Baz], | ||
| [FooBar::Baz, FooBar::Bar], | ||
| [FooBar::Bar, FooBar::Foo], | ||
| [FooBar::Foo, FooBar::Bar] => 2, | ||
|
|
||
| [FooBar::Baz, FooBar::Foo] => 3, | ||
| }; | ||
| } | ||
|
|
||
| enum TwoCases { | ||
| case Foo; | ||
| case Bar; | ||
| } | ||
|
|
||
| function getTwoCases(): TwoCases { | ||
| return TwoCases::Foo; | ||
| } | ||
|
|
||
| function testTwoCases(): void { | ||
| $first = getTwoCases(); | ||
| $second = getTwoCases(); | ||
|
|
||
| $type = match ([$first, $second]) { | ||
| [TwoCases::Foo, TwoCases::Foo] => 1, | ||
| [TwoCases::Bar, TwoCases::Bar] => 1, | ||
|
|
||
| [TwoCases::Bar, TwoCases::Foo] => 2, | ||
| [TwoCases::Foo, TwoCases::Bar] => 2, | ||
| }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| <?php // lint >= 8.0 | ||
|
|
||
| declare(strict_types = 1); | ||
|
|
||
| namespace Bug11453; | ||
|
|
||
| /** @return 1|2|3 */ | ||
| function getInt(): int { | ||
| return 1; | ||
| } | ||
|
|
||
| /** @return 'a'|'b'|'c' */ | ||
| function getString(): string { | ||
| return 'a'; | ||
| } | ||
|
|
||
| function test(): void { | ||
| $int = getInt(); | ||
| $string = getString(); | ||
|
|
||
| $type = match ([$int, $string]) { | ||
| [1, 'a'] => 'one-a', | ||
| [1, 'b'] => 'one-b', | ||
| [1, 'c'] => 'one-c', | ||
|
|
||
| [2, 'a'] => 'two-a', | ||
| [2, 'b'] => 'two-b', | ||
| [2, 'c'] => 'two-c', | ||
|
|
||
| [3, 'a'] => 'three-a', | ||
| [3, 'b'] => 'three-b', | ||
| [3, 'c'] => 'three-c', | ||
| }; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@phpstan-bot do we need a similar fix in
IntersectionType->tryRemove()or any otherType->tryRemove()implementation? try to come up with a failling test and implement a fix afterwardsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The working tree is clean — no code changes are needed. My investigation confirms that
IntersectionType::tryRemove()and all othertryRemove()implementations are not affected by the same normalization bug that this PR fixes inUnionType::tryRemove().