Skip to content

Commit

Permalink
VarianceAwareType as type decorator, not a standalone type
Browse files Browse the repository at this point in the history
  • Loading branch information
vudaltsov committed Feb 27, 2024
1 parent 15e24fd commit 5928c82
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 34 deletions.
5 changes: 0 additions & 5 deletions src/DefaultTypeVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,6 @@ public function value(Type $self, Type $type): mixed
return $this->default($self);
}

public function varianceAware(Type $self, Type $type, Variance $variance): mixed
{
return $this->default($self);
}

public function void(Type $self): mixed
{
return $this->default($self);
Expand Down
2 changes: 1 addition & 1 deletion src/NamedObjectType.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ final class NamedObjectType implements Type
{
/**
* @param non-empty-string $class
* @param list<Type> $templateArguments
* @param list<Type|VarianceAwareType> $templateArguments
*/
public function __construct(
private readonly string $class,
Expand Down
7 changes: 1 addition & 6 deletions src/TypeVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public function namedClassString(Type $self, Type $object): mixed;
/**
* @param Type<object> $self
* @param non-empty-string $class
* @param list<Type> $templateArguments
* @param list<Type|VarianceAwareType> $templateArguments
* @return TReturn
*/
public function namedObject(Type $self, string $class, array $templateArguments): mixed;
Expand Down Expand Up @@ -232,11 +232,6 @@ public function union(Type $self, array $types): mixed;
*/
public function value(Type $self, Type $type): mixed;

/**
* @return TReturn
*/
public function varianceAware(Type $self, Type $type, Variance $variance): mixed;

/**
* @param Type<void> $self
* @return TReturn
Expand Down
15 changes: 4 additions & 11 deletions src/VarianceAwareType.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,16 @@
namespace Typhoon\Type;

/**
* @internal
* @psalm-internal Typhoon\Type
* @api
* @template-covariant TType
* @implements Type<TType>
*/
final class VarianceAwareType implements Type
final class VarianceAwareType
{
/**
* @param Type<TType> $type
*/
public function __construct(
private readonly Type $type,
private readonly Variance $variance,
public readonly Type $type,
public readonly Variance $variance,
) {}

public function accept(TypeVisitor $visitor): mixed
{
return $visitor->varianceAware($this, $this->type, $this->variance);
}
}
12 changes: 1 addition & 11 deletions src/types.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ public static function nullable(Type $type): Type
* @param class-string<TObject>|non-empty-string $class
* @return ($class is class-string ? Type<TObject> : Type<object>)
*/
public static function object(string $class, Type ...$templateArguments): Type
public static function object(string $class, Type|VarianceAwareType ...$templateArguments): Type
{
if ($class === \Closure::class && $templateArguments === []) {
return self::closure;
Expand Down Expand Up @@ -421,16 +421,6 @@ public static function value(Type $type): Type
return new ValueType($type);
}

/**
* @template TType
* @param Type<TType> $type
* @return Type<TType>
*/
public static function varianceAware(Type $type, Variance $variance): Type
{
return new VarianceAwareType($type, $variance);
}

public function accept(TypeVisitor $visitor): mixed
{
return match ($this) {
Expand Down

0 comments on commit 5928c82

Please sign in to comment.