Skip to content

Commit

Permalink
fix: do not override invalid variadic parameter type
Browse files Browse the repository at this point in the history
  • Loading branch information
romm committed Apr 24, 2024
1 parent 1803d09 commit 3fd352c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use CuyZ\Valinor\Type\Type;
use CuyZ\Valinor\Type\Types\ArrayKeyType;
use CuyZ\Valinor\Type\Types\ArrayType;
use CuyZ\Valinor\Type\Types\UnresolvableType;
use ReflectionParameter;

/** @internal */
Expand All @@ -32,7 +33,7 @@ public function resolveTypeFor(ReflectionParameter $reflection): Type

$type = $this->typeResolver->resolveType($reflection->getType(), $docBlockType);

if ($reflection->isVariadic()) {
if ($reflection->isVariadic() && ! $type instanceof UnresolvableType) {
return new ArrayType(ArrayKeyType::default(), $type);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,19 @@ static function ($value): void {},
'string',
];
}

public function test_invalid_parameter_type_stays_invalid_when_variadic(): void
{
$reflection = new ReflectionParameter(
/**
* @param InvalidValue $value
*/
static function (...$value): void {},
'value',
);

$type = $this->resolver->resolveTypeFor($reflection);

self::assertInstanceOf(UnresolvableType::class, $type);
}
}

0 comments on commit 3fd352c

Please sign in to comment.