Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix infinite recursion for template intersection type accepts()
- Loading branch information
1 parent
29ca9b2
commit e4a1b67
Showing
3 changed files
with
56 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Bug7500; | ||
|
||
interface PositionEntityInterface { | ||
public function getPosition(): int; | ||
} | ||
interface TgEntityInterface {} | ||
|
||
abstract class HelloWorld | ||
{ | ||
/** | ||
* @phpstan-template T of PositionEntityInterface&TgEntityInterface | ||
* | ||
* @param iterable<T> $tgs | ||
* | ||
* @return array<T> | ||
* | ||
* @throws \Exception | ||
*/ | ||
public function computeForFrontByPosition($tgs) | ||
{ | ||
/** @phpstan-var array<T> $res */ | ||
$res = []; | ||
|
||
foreach ($tgs as $tgItem) { | ||
$position = $tgItem->getPosition(); | ||
|
||
if (!isset($res[$position])) { | ||
$res[$position] = $tgItem; | ||
} else { | ||
$tgItemToKeep = $this->compare($tgItem, $res[$position]); | ||
$res[$position] = $tgItemToKeep; | ||
} | ||
} | ||
ksort($res); | ||
|
||
return $res; | ||
} | ||
|
||
/** | ||
* @phpstan-template T of TgEntityInterface | ||
* @phpstan-param T $nextTg | ||
* @phpstan-param T $currentTg | ||
* @phpstan-return T | ||
*/ | ||
abstract protected function compare(TgEntityInterface $nextTg, TgEntityInterface $currentTg): TgEntityInterface; | ||
} |