From e9073eb0596e5d83fcf5e2e850800d1ea0086e7d Mon Sep 17 00:00:00 2001 From: orklah Date: Thu, 16 Dec 2021 23:39:23 +0100 Subject: [PATCH 1/3] doesn't infer empty for ReflectionClass::getAttributes without params --- stubs/Reflection.phpstub | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stubs/Reflection.phpstub b/stubs/Reflection.phpstub index 11dcf4537e2..f569ebfe829 100644 --- a/stubs/Reflection.phpstub +++ b/stubs/Reflection.phpstub @@ -51,7 +51,7 @@ class ReflectionClass implements Reflector { * @since 8.0 * @template TClass as object * @param class-string|null $name - * @return array> + * @return (TClass is empty ? array> : array>) */ public function getAttributes(?string $name = null, int $flags = 0): array {} } From 9583d6a7e7b870dae70f48fd7cb309db49edaebe Mon Sep 17 00:00:00 2001 From: orklah Date: Fri, 17 Dec 2021 00:12:54 +0100 Subject: [PATCH 2/3] invert stub, add test --- stubs/Reflection.phpstub | 2 +- tests/AttributeTest.php | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/stubs/Reflection.phpstub b/stubs/Reflection.phpstub index f569ebfe829..8cb358f8e03 100644 --- a/stubs/Reflection.phpstub +++ b/stubs/Reflection.phpstub @@ -51,7 +51,7 @@ class ReflectionClass implements Reflector { * @since 8.0 * @template TClass as object * @param class-string|null $name - * @return (TClass is empty ? array> : array>) + * @return (TClass is object ? array> : array>) */ public function getAttributes(?string $name = null, int $flags = 0): array {} } diff --git a/tests/AttributeTest.php b/tests/AttributeTest.php index 4912c532f75..1e54bcb6741 100644 --- a/tests/AttributeTest.php +++ b/tests/AttributeTest.php @@ -102,6 +102,31 @@ function foo(string $s) : void { [], '8.0' ], + 'testReflectingAllAttributes' => [ + 'getAttributes(); + scope($b); + } + } + + /** @param array> $a */ + function scope($_a):void{ + + } + ', + [], + [], + '8.0' + ], 'convertKeyedArray' => [ ' Date: Fri, 17 Dec 2021 00:16:50 +0100 Subject: [PATCH 3/3] fix test --- tests/AttributeTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/AttributeTest.php b/tests/AttributeTest.php index 1e54bcb6741..513c4b932fd 100644 --- a/tests/AttributeTest.php +++ b/tests/AttributeTest.php @@ -118,7 +118,7 @@ public function a(string $className): void } } - /** @param array> $a */ + /** @param array> $_a */ function scope($_a):void{ }