From 59558d531eb13867be93548231adbca9b77be867 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 | 19 +++++++ .../Rules/Properties/data/bug-6356.php | 52 +++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 tests/PHPStan/Rules/Properties/data/bug-6356.php diff --git a/tests/PHPStan/Rules/Properties/TypesAssignedToPropertiesRuleTest.php b/tests/PHPStan/Rules/Properties/TypesAssignedToPropertiesRuleTest.php index a9ac5b684d3..1d4f080b548 100644 --- a/tests/PHPStan/Rules/Properties/TypesAssignedToPropertiesRuleTest.php +++ b/tests/PHPStan/Rules/Properties/TypesAssignedToPropertiesRuleTest.php @@ -451,4 +451,23 @@ 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'], [ + [ + 'Property Bug6356\HelloWorld2::$details (array{name: string, age: int}) does not accept array{name: string, age: \'Forty-two\'}.', + 40, + ], + [ + 'Property Bug6356\HelloWorld2::$nestedDetails (array) does not accept non-empty-array.', + 42, + ], + [ + 'Property Bug6356\HelloWorld2::$nestedDetails (array) does not accept non-empty-array.', + 47, + ], + ]); + } + } 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 00000000000..9b02e32ab32 --- /dev/null +++ b/tests/PHPStan/Rules/Properties/data/bug-6356.php @@ -0,0 +1,52 @@ +> */ + private $lists; + + public function main(): void + { + for ($type = 0; $type < self::ENUM_COUNT; ++$type) + { + $this->lists[$type][] = true; + } + + print_r($this->lists); + } +} + +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'; + } +}