Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b973be4

Browse files
rvanvelzenondrejmirtes
authored andcommitted
Fix coalescing on an optional array offset
1 parent 2be4c7c commit b973be4

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

‎src/Analyser/MutatingScope.php‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1591,9 +1591,7 @@ private function resolveType(string $exprString, Expr $node): Type
15911591
return TypeCombinator::removeNull($leftType);
15921592
}
15931593

1594-
$rightType = $this->filterByFalseyValue(
1595-
new BinaryOp\NotIdentical($node->left, new ConstFetch(new Name('null'))),
1596-
)->getType($node->right);
1594+
$rightType = $this->filterByFalseyValue(new Expr\Isset_([$node->left]))->getType($node->right);
15971595

15981596
if ($result === null) {
15991597
return TypeCombinator::union(

‎tests/PHPStan/Analyser/NodeScopeResolverTest.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1408,6 +1408,7 @@ public function dataFileAsserts(): iterable
14081408
yield from $this->gatherAssertTypes(__DIR__ . '/data/conditional-vars.php');
14091409
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-5961.php');
14101410
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-10189.php');
1411+
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-10317.php');
14111412
}
14121413

14131414
/**
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug10317;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
/**
8+
* @param array{'foo': string, 'bar'?: string} $array
9+
*/
10+
function myfunction(array $array): void
11+
{
12+
$string = $array['bar'] ?? $array['foo'];
13+
assertType('string', $string);
14+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /