From 7254482d628f5eed48b56a1ebc306b5628b78766 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Fri, 23 Sep 2022 15:06:07 +0200 Subject: [PATCH] added regression test --- .../TypesAssignedToPropertiesRuleTest.php | 25 +++++++++++++++ .../Rules/Properties/data/bug-6356.php | 24 ++++++++++++++ .../Rules/Properties/data/bug-6356b.php | 31 +++++++++++++++++++ 3 files changed, 80 insertions(+) create mode 100644 tests/PHPStan/Rules/Properties/data/bug-6356.php create mode 100644 tests/PHPStan/Rules/Properties/data/bug-6356b.php diff --git a/tests/PHPStan/Rules/Properties/TypesAssignedToPropertiesRuleTest.php b/tests/PHPStan/Rules/Properties/TypesAssignedToPropertiesRuleTest.php index a9ac5b684d..09123d7331 100644 --- a/tests/PHPStan/Rules/Properties/TypesAssignedToPropertiesRuleTest.php +++ b/tests/PHPStan/Rules/Properties/TypesAssignedToPropertiesRuleTest.php @@ -451,4 +451,29 @@ public function testBug3383(): void $this->analyse([__DIR__ . '/data/bug-3383.php'], []); } + public function testBug6356(): void + { + $this->checkExplicitMixed = true; + $this->analyse([__DIR__ . '/data/bug-6356.php'], []); + } + + public function testBug6356b(): void + { + $this->checkExplicitMixed = true; + $this->analyse([__DIR__ . '/data/bug-6356b.php'], [ + [ + 'Property Bug6356b\HelloWorld2::$details (array{name: string, age: int}) does not accept array{name: string, age: \'Forty-two\'}.', + 19, + ], + [ + 'Property Bug6356b\HelloWorld2::$nestedDetails (array) does not accept non-empty-array.', + 21, + ], + [ + 'Property Bug6356b\HelloWorld2::$nestedDetails (array) does not accept non-empty-array.', + 26, + ], + ]); + } + } diff --git a/tests/PHPStan/Rules/Properties/data/bug-6356.php b/tests/PHPStan/Rules/Properties/data/bug-6356.php new file mode 100644 index 0000000000..4f5208a761 --- /dev/null +++ b/tests/PHPStan/Rules/Properties/data/bug-6356.php @@ -0,0 +1,24 @@ +> */ + private $lists; + + public function main(): void + { + for ($type = 0; $type < self::ENUM_COUNT; ++$type) + { + $this->lists[$type][] = true; + } + + print_r($this->lists); + } +} diff --git a/tests/PHPStan/Rules/Properties/data/bug-6356b.php b/tests/PHPStan/Rules/Properties/data/bug-6356b.php new file mode 100644 index 0000000000..3b974edc78 --- /dev/null +++ b/tests/PHPStan/Rules/Properties/data/bug-6356b.php @@ -0,0 +1,31 @@ += 7.4 + +namespace Bug6356b; + +class HelloWorld2 +{ + /** + * @var array{name:string,age:int} + */ + public array $details; + /** + * @var array + */ + public array $nestedDetails; + + public function doSomething(): void + { + $this->details ['name'] = 'Douglas Adams'; + $this->details ['age'] = 'Forty-two'; + + $this->nestedDetails [] = [ + 'name' => 'Bilbo Baggins', + 'age' => 'Eleventy-one', + ]; + + $this->nestedDetails [12] ['age'] = 'Twelve'; + $this->nestedDetails [] ['age'] = 'Five'; + + $this->nestedDetails [99] ['name'] = 'nothing'; + } +}