-
Notifications
You must be signed in to change notification settings - Fork 575
Add array assertions about unsealed arrays #5722
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
base: 2.2.x
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -93,3 +93,14 @@ function foo10(array $array) | |
| assertType("*NEVER*", array_flip($array)); // this could be array<string, int>&hasOffsetValue(17, 'bar') according to https://3v4l.org/1TAFk | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * @param array{0: 1, 1: 2, 2: 3} $sealed | ||
| * @param array{0: 1, 1: 2, 2: 3, ...<int, bool>} $unsealed | ||
| */ | ||
| function sealedArrayFlip(array $sealed, array $unsealed): void | ||
| { | ||
| assertType('array{1: 0, 2: 1, 3: 2}', array_flip($sealed)); | ||
| assertType('array{1: int, 2: 1, 3: 2, 0?: int, ...<0|1, int>}', array_flip($unsealed)); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure what's expected here, currently the type is but this gives This can be fixed in the ConstantArrayType::flipArray with an extra but in the same way I dunno if you like the result with the useless |
||
| assertType('int', array_flip($unsealed)[1]); | ||
| } | ||
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.
This is correct.
But you might want to improve the array because
...<0|1, 'b'>is kinda complicated for nothing:1key already exists, we might want to simplify tomaybe ?