-
Notifications
You must be signed in to change notification settings - Fork 465
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not lose generic type when the closure has native return type
Closes phpstan/phpstan#7281
- Loading branch information
1 parent
6d64074
commit 7e9cd45
Showing
5 changed files
with
137 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
<?php | ||
|
||
namespace Bug7281; | ||
|
||
use function PHPStan\Testing\assertType; | ||
|
||
class Percentage {} | ||
|
||
/** | ||
* @template T | ||
*/ | ||
final class Timeline {} | ||
|
||
/** | ||
* @template K of array-key | ||
* @template T | ||
* @template U | ||
* | ||
* @param array<K, T> $array | ||
* @param (callable(T, K): U) $fn | ||
* | ||
* @return array<K, U> | ||
*/ | ||
function map(array $array, callable $fn): array | ||
{ | ||
/** @phpstan-ignore-next-line */ | ||
return array_map($fn, $array); | ||
} | ||
|
||
function (): void { | ||
/** | ||
* @var array<int, Timeline<Percentage>> $timelines | ||
*/ | ||
$timelines = []; | ||
|
||
assertType('array<int, Bug7281\\Timeline<Bug7281\\Percentage>>', map( | ||
$timelines, | ||
static function (Timeline $timeline): Timeline { | ||
return $timeline; | ||
}, | ||
)); | ||
assertType('array<int, Bug7281\\Timeline<Bug7281\\Percentage>>', map( | ||
$timelines, | ||
static function ($timeline) { | ||
return $timeline; | ||
}, | ||
)); | ||
|
||
assertType('array<int, Bug7281\\Timeline<Bug7281\\Percentage>>', map( | ||
$timelines, | ||
static fn (Timeline $timeline): Timeline => $timeline, | ||
)); | ||
assertType('array<int, Bug7281\\Timeline<Bug7281\\Percentage>>', map( | ||
$timelines, | ||
static fn ($timeline) => $timeline, | ||
)); | ||
|
||
assertType('array<int, Bug7281\\Timeline<Bug7281\\Percentage>>', array_map( | ||
static function (Timeline $timeline): Timeline { | ||
return $timeline; | ||
}, | ||
$timelines, | ||
)); | ||
assertType('array<int, Bug7281\\Timeline<Bug7281\\Percentage>>', array_map( | ||
static function ($timeline) { | ||
return $timeline; | ||
}, | ||
$timelines, | ||
)); | ||
|
||
assertType('array<int, Bug7281\\Timeline<Bug7281\\Percentage>>', array_map( | ||
static fn (Timeline $timeline): Timeline => $timeline, | ||
$timelines, | ||
)); | ||
assertType('array<int, Bug7281\\Timeline<Bug7281\\Percentage>>', array_map( | ||
static fn ($timeline) => $timeline, | ||
$timelines, | ||
)); | ||
|
||
assertType('array<int, Bug7281\\Timeline<Bug7281\\Percentage>>', array_map( | ||
static function (Timeline $timeline) { | ||
return $timeline; | ||
}, | ||
$timelines, | ||
)); | ||
assertType('array<int, Bug7281\\Timeline<Bug7281\\Percentage>>', array_map( | ||
static function ($timeline): Timeline { | ||
return $timeline; | ||
}, | ||
$timelines, | ||
)); | ||
|
||
assertType('array<int, Bug7281\\Timeline<Bug7281\\Percentage>>', array_map( | ||
static fn (Timeline $timeline) => $timeline, | ||
$timelines, | ||
)); | ||
assertType('array<int, Bug7281\\Timeline<Bug7281\\Percentage>>', array_map( | ||
static fn ($timeline): Timeline => $timeline, | ||
$timelines, | ||
)); | ||
}; |
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