From 0dd3d0c4ec5f1b50adbc5f04ef780c977d81a835 Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Mon, 28 Feb 2022 13:20:13 +0100 Subject: [PATCH] Level 9 regression tests Closes https://github.com/phpstan/phpstan/issues/6464 Closes https://github.com/phpstan/phpstan/issues/6423 Closes https://github.com/phpstan/phpstan/issues/6418 Closes https://github.com/phpstan/phpstan/issues/6230 Closes https://github.com/phpstan/phpstan/issues/5860 --- .../Rules/Methods/CallMethodsRuleTest.php | 18 ++++++++ .../Rules/Methods/ReturnTypeRuleTest.php | 18 ++++++++ tests/PHPStan/Rules/Methods/data/bug-5860.php | 20 +++++++++ tests/PHPStan/Rules/Methods/data/bug-6230.php | 43 +++++++++++++++++++ tests/PHPStan/Rules/Methods/data/bug-6418.php | 19 ++++++++ tests/PHPStan/Rules/Methods/data/bug-6423.php | 34 +++++++++++++++ tests/PHPStan/Rules/Methods/data/bug-6464.php | 20 +++++++++ 7 files changed, 172 insertions(+) create mode 100644 tests/PHPStan/Rules/Methods/data/bug-5860.php create mode 100644 tests/PHPStan/Rules/Methods/data/bug-6230.php create mode 100644 tests/PHPStan/Rules/Methods/data/bug-6418.php create mode 100644 tests/PHPStan/Rules/Methods/data/bug-6423.php create mode 100644 tests/PHPStan/Rules/Methods/data/bug-6464.php diff --git a/tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php b/tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php index 9eaa82d4cb..e0dd1ad3fa 100644 --- a/tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php +++ b/tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php @@ -2384,4 +2384,22 @@ public function testBug6118(): void $this->analyse([__DIR__ . '/data/bug-6118.php'], []); } + public function testBug6464(): void + { + $this->checkThisOnly = false; + $this->checkNullables = true; + $this->checkUnionTypes = true; + $this->checkExplicitMixed = true; + $this->analyse([__DIR__ . '/data/bug-6464.php'], []); + } + + public function testBug6423(): void + { + $this->checkThisOnly = false; + $this->checkNullables = true; + $this->checkUnionTypes = true; + $this->checkExplicitMixed = true; + $this->analyse([__DIR__ . '/data/bug-6423.php'], []); + } + } diff --git a/tests/PHPStan/Rules/Methods/ReturnTypeRuleTest.php b/tests/PHPStan/Rules/Methods/ReturnTypeRuleTest.php index a637934679..dd17e454e9 100644 --- a/tests/PHPStan/Rules/Methods/ReturnTypeRuleTest.php +++ b/tests/PHPStan/Rules/Methods/ReturnTypeRuleTest.php @@ -603,4 +603,22 @@ public function testBug6589(): void ]); } + public function testBug6418(): void + { + $this->checkExplicitMixed = true; + $this->analyse([__DIR__ . '/data/bug-6418.php'], []); + } + + public function testBug6230(): void + { + $this->checkExplicitMixed = true; + $this->analyse([__DIR__ . '/data/bug-6230.php'], []); + } + + public function testBug5860(): void + { + $this->checkExplicitMixed = true; + $this->analyse([__DIR__ . '/data/bug-5860.php'], []); + } + } diff --git a/tests/PHPStan/Rules/Methods/data/bug-5860.php b/tests/PHPStan/Rules/Methods/data/bug-5860.php new file mode 100644 index 0000000000..f41cab6c93 --- /dev/null +++ b/tests/PHPStan/Rules/Methods/data/bug-5860.php @@ -0,0 +1,20 @@ + $it + * @return ?iterable + */ + function test($it): ?iterable + { + return $it; + } + +} + +/** + * @template T + */ +class Example +{ + /** + * @var ?iterable + */ + private $input; + + + /** + * @param iterable $input + */ + public function __construct(iterable $input) + { + $this->input = $input; + } + + /** @return ?iterable */ + public function get(): ?iterable + { + return $this->input; + } +} diff --git a/tests/PHPStan/Rules/Methods/data/bug-6418.php b/tests/PHPStan/Rules/Methods/data/bug-6418.php new file mode 100644 index 0000000000..d1fb02a4fe --- /dev/null +++ b/tests/PHPStan/Rules/Methods/data/bug-6418.php @@ -0,0 +1,19 @@ + $foos + */ + function doFoo(?array $foos = null): void {} + + /** + * @return list + */ + function doBar(): array + { + return [ + 'hello', + 'world', + ]; + } + + function doBaz() + { + $this->doFoo([ + 'foo', + 'bar', + ...$this->doBar(), + ]); + } + +} diff --git a/tests/PHPStan/Rules/Methods/data/bug-6464.php b/tests/PHPStan/Rules/Methods/data/bug-6464.php new file mode 100644 index 0000000000..0cc01b2790 --- /dev/null +++ b/tests/PHPStan/Rules/Methods/data/bug-6464.php @@ -0,0 +1,20 @@ + $g */ + public function foo(\Generator $g): void; +} + +class Bar +{ + + function test(Foo $foo): void { + $foo->foo((function(string $str) { + yield $str; + })('hello')); + } + +}