From 2f136f2afa92d470317c6fb711bf7c0b08b60218 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 9 Mar 2026 17:23:30 +0000 Subject: [PATCH] Fix false positive unresolvable template type on optional variadic params - When a template type is only used on a variadic parameter and no arguments are passed, it was incorrectly reported as unresolvable - Fixed by inferring NeverType for variadic parameters with no arguments in GenericParametersAcceptorResolver, since an empty variadic means the element type is never - Added regression tests in both rule test and NSRT format Closes https://github.com/phpstan/phpstan/issues/2572 --- .../GenericParametersAcceptorResolver.php | 3 +++ tests/PHPStan/Analyser/nsrt/bug-2572.php | 27 +++++++++++++++++++ .../CallToFunctionParametersRuleTest.php | 5 ++++ .../PHPStan/Rules/Functions/data/bug-2572.php | 25 +++++++++++++++++ 4 files changed, 60 insertions(+) create mode 100644 tests/PHPStan/Analyser/nsrt/bug-2572.php create mode 100644 tests/PHPStan/Rules/Functions/data/bug-2572.php diff --git a/src/Reflection/GenericParametersAcceptorResolver.php b/src/Reflection/GenericParametersAcceptorResolver.php index 27d8cfc11c..6e560dd2fd 100644 --- a/src/Reflection/GenericParametersAcceptorResolver.php +++ b/src/Reflection/GenericParametersAcceptorResolver.php @@ -10,6 +10,7 @@ use PHPStan\Type\Generic\TemplateTypeMap; use PHPStan\Type\Generic\TemplateTypeVarianceMap; use PHPStan\Type\MixedType; +use PHPStan\Type\NeverType; use PHPStan\Type\Type; use PHPStan\Type\TypeCombinator; use function array_key_exists; @@ -61,6 +62,8 @@ public static function resolve(array $argTypes, ParametersAcceptor $parametersAc $argType = $namedArgTypes[$param->getName()]; } elseif ($param->getDefaultValue() !== null) { $argType = $param->getDefaultValue(); + } elseif ($param->isVariadic()) { + $argType = new NeverType(); } else { continue; } diff --git a/tests/PHPStan/Analyser/nsrt/bug-2572.php b/tests/PHPStan/Analyser/nsrt/bug-2572.php new file mode 100644 index 0000000000..a1f332e492 --- /dev/null +++ b/tests/PHPStan/Analyser/nsrt/bug-2572.php @@ -0,0 +1,27 @@ +analyse([__DIR__ . '/data/bug-13247.php'], []); } + public function testBug2572(): void + { + $this->analyse([__DIR__ . '/data/bug-2572.php'], []); + } + } diff --git a/tests/PHPStan/Rules/Functions/data/bug-2572.php b/tests/PHPStan/Rules/Functions/data/bug-2572.php new file mode 100644 index 0000000000..e56c50f837 --- /dev/null +++ b/tests/PHPStan/Rules/Functions/data/bug-2572.php @@ -0,0 +1,25 @@ +