diff --git a/.github/workflows/e2e-tests.yml b/.github/workflows/e2e-tests.yml index ae29efb84c7..c69d2c72126 100644 --- a/.github/workflows/e2e-tests.yml +++ b/.github/workflows/e2e-tests.yml @@ -1407,6 +1407,20 @@ jobs: - script: | cd e2e/bug-14305 ../../bin/phpstan + - script: | + # A userland class named `Resource` is a class, not the `resource` pseudo-type, + # on every phpVersion: https://phpstan.org/r/47fe50ab-e9de-4e20-8093-b24400e53d66 + # The `resource` native type in the pre-PHP 8 PhpStorm stubs is the pseudo-type, + # which is what https://github.com/phpstan/phpstan/issues/15141 was about. + cd e2e/bug-15141 + OUTPUT=$(../bashunit -a exit_code "1" "../../bin/phpstan analyse --no-progress --error-format raw") + echo "$OUTPUT" + ../bashunit -a contains 'test.php:13:Parameter #1 $r of function doFoo expects Resource, resource given.' "$OUTPUT" + ../bashunit -a equals '1' "$(echo "$OUTPUT" | grep -Ec '^/.+:[0-9]+:')" + OUTPUT=$(../bashunit -a exit_code "1" "../../bin/phpstan analyse --no-progress --error-format raw -c php74.neon") + echo "$OUTPUT" + ../bashunit -a contains 'test.php:13:Parameter #1 $r of function doFoo expects Resource, resource given.' "$OUTPUT" + ../bashunit -a equals '1' "$(echo "$OUTPUT" | grep -Ec '^/.+:[0-9]+:')" - script: | cd e2e/composer-and-phpstan-version-config composer install --ignore-platform-reqs diff --git a/e2e/bug-15141/php74.neon b/e2e/bug-15141/php74.neon new file mode 100644 index 00000000000..0501c78696d --- /dev/null +++ b/e2e/bug-15141/php74.neon @@ -0,0 +1,6 @@ +parameters: + level: 10 + phpVersion: 70400 + paths: + - test.php + - resource-pseudo-type.php diff --git a/e2e/bug-15141/phpstan.neon b/e2e/bug-15141/phpstan.neon new file mode 100644 index 00000000000..55b68fdc257 --- /dev/null +++ b/e2e/bug-15141/phpstan.neon @@ -0,0 +1,4 @@ +parameters: + level: 10 + paths: + - test.php diff --git a/e2e/bug-15141/resource-pseudo-type.php b/e2e/bug-15141/resource-pseudo-type.php new file mode 100644 index 00000000000..c81627cbb37 --- /dev/null +++ b/e2e/bug-15141/resource-pseudo-type.php @@ -0,0 +1,9 @@ +analyse([__DIR__ . '/data/bug-15168.php'], []); } + #[RequiresPhp('< 8.0.0')] + public function testBug15141(): void + { + $this->analyse([__DIR__ . '/data/bug-15141.php'], []); + } + + public function testBug15141ResourceClass(): void + { + $this->analyse([__DIR__ . '/data/bug-15141-resource-class.php'], [ + [ + 'Parameter #1 $r of function bug15141TakesResourceClass expects Resource, resource given.', + 16, + ], + ]); + } + } diff --git a/tests/PHPStan/Rules/Functions/data/bug-15141-resource-class.php b/tests/PHPStan/Rules/Functions/data/bug-15141-resource-class.php new file mode 100644 index 00000000000..cb097edf6e2 --- /dev/null +++ b/tests/PHPStan/Rules/Functions/data/bug-15141-resource-class.php @@ -0,0 +1,18 @@ +