From 3fd352c5564739a0fb8dc78ee22bc4152aaaa93a Mon Sep 17 00:00:00 2001 From: Romain Canon Date: Wed, 24 Apr 2024 13:50:00 +0200 Subject: [PATCH] fix: do not override invalid variadic parameter type --- .../TypeResolver/ParameterTypeResolver.php | 3 ++- .../TypeResolver/ParameterTypeResolverTest.php | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/Definition/Repository/Reflection/TypeResolver/ParameterTypeResolver.php b/src/Definition/Repository/Reflection/TypeResolver/ParameterTypeResolver.php index bab24b08..0a732829 100644 --- a/src/Definition/Repository/Reflection/TypeResolver/ParameterTypeResolver.php +++ b/src/Definition/Repository/Reflection/TypeResolver/ParameterTypeResolver.php @@ -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 */ @@ -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); } diff --git a/tests/Functional/Definition/Repository/Reflection/TypeResolver/ParameterTypeResolverTest.php b/tests/Functional/Definition/Repository/Reflection/TypeResolver/ParameterTypeResolverTest.php index aad55e8a..72849650 100644 --- a/tests/Functional/Definition/Repository/Reflection/TypeResolver/ParameterTypeResolverTest.php +++ b/tests/Functional/Definition/Repository/Reflection/TypeResolver/ParameterTypeResolverTest.php @@ -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); + } }