Skip to content

Commit

Permalink
add regression test for phpstan/phpstan#7805
Browse files Browse the repository at this point in the history
  • Loading branch information
rajyan committed Dec 14, 2022
1 parent b76e7b1 commit 8f06b2d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/PHPStan/Analyser/NodeScopeResolverTest.php
Expand Up @@ -1138,6 +1138,7 @@ public function dataFileAsserts(): iterable
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-8467b.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/PDOStatement.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/discussion-8447.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-7805.php');
}

/**
Expand Down
33 changes: 33 additions & 0 deletions tests/PHPStan/Analyser/data/bug-7805.php
@@ -0,0 +1,33 @@
<?php declare(strict_types = 1);

use function PHPStan\Testing\assertNativeType;
use function PHPStan\Testing\assertType;

/**
* @phpstan-param array{help?: null} $params
*/
function foo(array $params)
{
assertType('array{help?: null}', $params);
assertNativeType('array', $params);
if (array_key_exists('help', $params)) {
assertType('array{help: null}', $params);
assertNativeType("array&hasOffset('help')", $params);
unset($params['help']);

assertType('array{}', $params);
assertNativeType("array<mixed~'help', mixed>", $params);
$params = $params === [] ? ['list'] : $params;
assertType("array{'list'}", $params);
assertNativeType("array{'list'}", $params);
// assertNativeType("array<mixed~'help', mixed>|array{'list'}", $params); // not working yet
array_unshift($params, 'help');
assertType("array{'help', 'list'}", $params);
assertNativeType("array{'list'}", $params);
// assertNativeType("array", $params); // not working yet
}
assertType("array{}|array{'help', 'list'}", $params);
assertNativeType('array', $params);

return $params;
}

0 comments on commit 8f06b2d

Please sign in to comment.