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 553ed1b
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 0 deletions.
Expand Up @@ -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<array{name: string, age: int}>) does not accept non-empty-array<array{name: string, age: \'Eleventy-one\'|int}>.',
21,
],
[
'Property Bug6356b\HelloWorld2::$nestedDetails (array<array{name: string, age: int}>) does not accept non-empty-array<array{name: string, age: \'Twelve\'|int}>.',
26,
],
]);
}

}
24 changes: 24 additions & 0 deletions tests/PHPStan/Rules/Properties/data/bug-6356.php
@@ -0,0 +1,24 @@
<?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);
}
}
31 changes: 31 additions & 0 deletions tests/PHPStan/Rules/Properties/data/bug-6356b.php
@@ -0,0 +1,31 @@
<?php declare(strict_types=1); // lint >= 7.4

namespace Bug6356b;

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 553ed1b

Please sign in to comment.