From 7ec22a14227f7856c8e1ec476f70fc5189f81fd3 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 31 Aug 2020 20:11:36 +0100 Subject: [PATCH 1/2] TypeNodeResolver: variadics are always optional this fixes phpstan/phpstan#3798. --- src/PhpDoc/TypeNodeResolver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PhpDoc/TypeNodeResolver.php b/src/PhpDoc/TypeNodeResolver.php index d5c331884c..b9597cb59c 100644 --- a/src/PhpDoc/TypeNodeResolver.php +++ b/src/PhpDoc/TypeNodeResolver.php @@ -451,7 +451,7 @@ function (CallableTypeParameterNode $parameterNode) use ($nameScope, &$isVariadi $isVariadic = $isVariadic || $parameterNode->isVariadic; return new NativeParameterReflection( $parameterNode->parameterName, - $parameterNode->isOptional, + $parameterNode->isOptional || $parameterNode->isVariadic, $this->resolve($parameterNode->type, $nameScope), $parameterNode->isReference ? PassedByReference::createCreatesNewVariable() : PassedByReference::createNo(), $parameterNode->isVariadic, From 7b90f19c3a640e6a8fdcc0f6507bee453c15bbb3 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 31 Aug 2020 20:21:37 +0100 Subject: [PATCH 2/2] added test case for phpstan/phpstan#3798 --- tests/PHPStan/Analyser/AnalyserIntegrationTest.php | 6 ++++++ tests/PHPStan/Analyser/data/bug-3798.php | 10 ++++++++++ 2 files changed, 16 insertions(+) create mode 100644 tests/PHPStan/Analyser/data/bug-3798.php diff --git a/tests/PHPStan/Analyser/AnalyserIntegrationTest.php b/tests/PHPStan/Analyser/AnalyserIntegrationTest.php index 49026eaec2..afbda2777d 100644 --- a/tests/PHPStan/Analyser/AnalyserIntegrationTest.php +++ b/tests/PHPStan/Analyser/AnalyserIntegrationTest.php @@ -273,6 +273,12 @@ public function testBug3379(): void $this->assertSame('Reflection error: Could not locate constant "SOME_UNKNOWN_CONST" while evaluating expression in Bug3379\Foo at line 8', $errors[1]->getMessage()); } + public function testBug3798(): void + { + $errors = $this->runAnalyse(__DIR__ . '/data/bug-3798.php'); + $this->assertCount(0, $errors); + } + /** * @param string $file * @return \PHPStan\Analyser\Error[] diff --git a/tests/PHPStan/Analyser/data/bug-3798.php b/tests/PHPStan/Analyser/data/bug-3798.php new file mode 100644 index 0000000000..b3aa28897c --- /dev/null +++ b/tests/PHPStan/Analyser/data/bug-3798.php @@ -0,0 +1,10 @@ +