-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
78 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Typhoon\Type; | ||
|
||
/** | ||
* @api | ||
* @psalm-immutable | ||
*/ | ||
enum Variance | ||
{ | ||
case INVARIANT; | ||
case COVARIANT; | ||
case CONTRAVARIANT; | ||
case BIVARIANT; | ||
} |
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,38 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Typhoon\Type; | ||
|
||
/** | ||
* @api | ||
* @template-covariant TType | ||
* @implements Type<TType> | ||
*/ | ||
final class VarianceAwareType implements Type | ||
{ | ||
/** | ||
* @var Type<TType> | ||
*/ | ||
public readonly Type $type; | ||
|
||
public readonly Variance $variance; | ||
|
||
/** | ||
* @internal | ||
* @psalm-internal Typhoon\Type | ||
* @param Type<TType> $type | ||
*/ | ||
public function __construct( | ||
Type $type, | ||
Variance $variance, | ||
) { | ||
$this->type = $type; | ||
$this->variance = $variance; | ||
} | ||
|
||
public function accept(TypeVisitor $visitor): mixed | ||
{ | ||
return $visitor->visitVarianceAware($this); | ||
} | ||
} |
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,9 @@ | ||
--FILE-- | ||
<?php | ||
|
||
namespace Typhoon\Type; | ||
|
||
$_type = PsalmTest::extractType(new VarianceAwareType(StringType::type, Variance::INVARIANT)); | ||
/** @psalm-check-type-exact $_type = string */ | ||
|
||
--EXPECT-- |