Skip to content

Commit

Permalink
added regression test
Browse files Browse the repository at this point in the history
  • Loading branch information
clxmstaab committed Sep 23, 2022
1 parent 0f2225c commit 59558d5
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
Expand Up @@ -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<array{name: string, age: int}>) does not accept non-empty-array<array{name: string, age: \'Eleventy-one\'|int}>.',
42,
],
[
'Property Bug6356\HelloWorld2::$nestedDetails (array<array{name: string, age: int}>) does not accept non-empty-array<array{name: string, age: \'Twelve\'|int}>.',
47,
],
]);
}

}
52 changes: 52 additions & 0 deletions tests/PHPStan/Rules/Properties/data/bug-6356.php
@@ -0,0 +1,52 @@
<?php declare(strict_types=1);

namespace Bug6356;

class HelloWorld
{
const ENUM_ZERO = 0;
const ENUM_ONE = 1;
const ENUM_TWO = 2;
const ENUM_COUNT = 3;

/** @var array<HelloWorld::*, array<int, bool>> */
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<array{name:string,age:int}>
*/
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';
}
}

0 comments on commit 59558d5

Please sign in to comment.