Skip to content

Commit

Permalink
Merge pull request #22 from weirdan/fix-partition-type
Browse files Browse the repository at this point in the history
Fixed Collection::partition closure type
  • Loading branch information
weirdan committed Jul 20, 2019
2 parents 30ea862 + bd21816 commit e554698
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion stubs/Collections.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public function forAll(Closure $p);
public function map(Closure $func);

/**
* @param Closure(TValue=):bool $p
* @param Closure(TKey=,TValue=):bool $p
* @return array{0:Collection<TKey,TValue>,1:Collection<TKey,TValue>}
*/
public function partition(Closure $p);
Expand Down
16 changes: 8 additions & 8 deletions tests/acceptance/Collections.feature
Original file line number Diff line number Diff line change
Expand Up @@ -572,11 +572,11 @@ Feature: Collections
"""
/** @var Collection<int,string> */
$c = new ArrayCollection(["a", "b", "c"]);
atan($c->partition(function(string $_p): bool { return (bool) rand(0,1); }));
atan($c->partition(function(int $_k, string $_p): bool { return (bool) rand(0,1); }));
"""
When I run Psalm
Then I see these errors
| Type | Message |
| Type | Message |
| InvalidArgument | Argument 1 of atan expects float, array{0:%Doctrine\Common\Collections\Collection<int, string>, 1:%Doctrine\Common\Collections\Collection<int, string>} provided |
And I see no other errors

Expand All @@ -586,12 +586,12 @@ Feature: Collections
"""
/** @var Collection<int,string> */
$c = new ArrayCollection(["a", "b", "c"]);
$c->partition(function(int $_p): bool { return (bool) rand(0,1); });
$c->partition(function(string $_p): bool { return (bool) rand(0,1); });
"""
When I run Psalm
Then I see these errors
| Type | Message |
| InvalidScalarArgument | Argument 1 of Doctrine\Common\Collections\Collection::partition expects Closure(string=):bool, Closure(int):bool provided |
| Type | Message |
| InvalidScalarArgument | Argument 1 of Doctrine\Common\Collections\Collection::partition expects Closure(int=, string=):bool, Closure(string):bool provided |
And I see no other errors

@Collection::partition
Expand All @@ -600,12 +600,12 @@ Feature: Collections
"""
/** @var Collection<int,string> */
$c = new ArrayCollection(["a", "b", "c"]);
$c->partition(function(string $_p): int { return rand(0,1); });
$c->partition(function(int $_p): int { return rand(0,1); });
"""
When I run Psalm
Then I see these errors
| Type | Message |
| InvalidScalarArgument | Argument 1 of Doctrine\Common\Collections\Collection::partition expects Closure(string=):bool, Closure(string):int provided |
| Type | Message |
| InvalidScalarArgument | Argument 1 of Doctrine\Common\Collections\Collection::partition expects Closure(int=, string=):bool, Closure(int):int provided |
And I see no other errors

@Collection::partition
Expand Down

0 comments on commit e554698

Please sign in to comment.