Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VarianceAwareType as type decorator, not a standalone type #40

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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