-
Notifications
You must be signed in to change notification settings - Fork 461
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Keep iterable key type and value type when subtracting from iterable
- Loading branch information
1 parent
3b109a7
commit c1f7aaf
Showing
6 changed files
with
74 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,50 @@ | ||
<?php | ||
|
||
namespace Bug4498; | ||
|
||
use function PHPStan\Analyser\assertType; | ||
|
||
class Foo | ||
{ | ||
|
||
/** | ||
* @param iterable<TKey, TValue> $iterable | ||
* | ||
* @return iterable<TKey, TValue> | ||
* | ||
* @template TKey | ||
* @template TValue | ||
*/ | ||
public function fcn(iterable $iterable): iterable | ||
{ | ||
if ($iterable instanceof \Traversable) { | ||
assertType('iterable<TKey (method Bug4498\Foo::fcn(), argument), TValue (method Bug4498\Foo::fcn(), argument)>&Traversable', $iterable); | ||
return $iterable; | ||
} | ||
|
||
assertType('array<TKey (method Bug4498\Foo::fcn(), argument), TValue (method Bug4498\Foo::fcn(), argument)>', $iterable); | ||
|
||
return $iterable; | ||
} | ||
|
||
/** | ||
* @param iterable<TKey, TValue> $iterable | ||
* | ||
* @return iterable<TKey, TValue> | ||
* | ||
* @template TKey | ||
* @template TValue | ||
*/ | ||
public function bar(iterable $iterable): iterable | ||
{ | ||
if (is_array($iterable)) { | ||
assertType('array<TKey (method Bug4498\Foo::bar(), argument), TValue (method Bug4498\Foo::bar(), argument)>', $iterable); | ||
return $iterable; | ||
} | ||
|
||
assertType('Traversable<TKey (method Bug4498\Foo::bar(), argument), TValue (method Bug4498\Foo::bar(), argument)>', $iterable); | ||
|
||
return $iterable; | ||
} | ||
|
||
} |
This file contains 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 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