Skip to content

Commit

Permalink
Added test for function(method)s with pass by reference params
Browse files Browse the repository at this point in the history
  • Loading branch information
ryium committed Dec 17, 2022
1 parent b650894 commit 325c917
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
8 changes: 6 additions & 2 deletions tests/PHPStan/Analyser/data/bug-8084.php
Expand Up @@ -2,15 +2,19 @@

namespace Bug8084;

use Exception;
use function array_shift;
use function PHPStan\Testing\assertType;

class Bug8084
{
/**
* @param array{a: 0, b?: 1} $arr
* @throws Exception
*/
public function run(array $arr): void
{
/** @var array{a: 0, b?: 1} $arr */
assertType('0', array_shift($arr) ?? throw new \Exception());
assertType('0', array_shift($arr) ?? throw new Exception());
assertType('1|null', array_shift($arr));
}
}
8 changes: 8 additions & 0 deletions tests/PHPStan/Rules/Variables/NullCoalesceRuleTest.php
Expand Up @@ -360,4 +360,12 @@ public function testBug7968(): void
$this->analyse([__DIR__ . '/data/bug-7968.php'], []);
}

public function testBug8084(): void
{
$this->treatPhpDocTypesAsCertain = true;
$this->strictUnnecessaryNullsafePropertyFetch = true;

$this->analyse([__DIR__ . '/data/bug-8084.php'], []);
}

}
19 changes: 19 additions & 0 deletions tests/PHPStan/Rules/Variables/data/bug-8084.php
@@ -0,0 +1,19 @@
<?php

namespace Bug8084;

use Exception;
use function array_shift;
use function PHPStan\Testing\assertType;

class Bug8084
{
/**
* @param array{a?: 0} $arr
* @throws Exception
*/
public function run(array $arr): void
{
assertType('0|null', array_shift($arr) ?? throw new Exception());
}
}

0 comments on commit 325c917

Please sign in to comment.