Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Type] add support for variadic intersection types (#185)
- Loading branch information
Showing
4 changed files
with
97 additions
and
20 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,46 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Psl\Collection\Map; | ||
use Psl\Collection\Vector; | ||
use Psl\Result\ResultInterface; | ||
use Psl\Type; | ||
|
||
/** | ||
* @psalm-suppress UnusedParam | ||
* | ||
* @param Map&ResultInterface&stdClass&Vector $value | ||
*/ | ||
function takes_valid_intersection($value): void | ||
{ | ||
} | ||
|
||
function test(): void | ||
{ | ||
/** @psalm-suppress MissingThrowsDocblock */ | ||
$old_school_codec = Type\intersection( | ||
Type\object(Map::class), | ||
Type\intersection( | ||
Type\object(ResultInterface::class), | ||
Type\intersection( | ||
Type\object(stdClass::class), | ||
Type\object(Vector::class), | ||
) | ||
), | ||
); | ||
|
||
/** @psalm-suppress MissingThrowsDocblock */ | ||
$new_codec = Type\intersection( | ||
Type\object(Map::class), | ||
Type\object(ResultInterface::class), | ||
Type\object(stdClass::class), | ||
Type\object(Vector::class), | ||
); | ||
|
||
/** @psalm-suppress MissingThrowsDocblock */ | ||
takes_valid_intersection($old_school_codec->assert('any')); | ||
|
||
/** @psalm-suppress MissingThrowsDocblock */ | ||
takes_valid_intersection($new_codec->assert('any')); | ||
} |
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