Skip to content

Commit 9571283

Browse files
herndlmondrejmirtes
authored andcommitted
Guard Equal expression specification with empty array on both sides
1 parent 6fa7c90 commit 9571283

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

src/Analyser/TypeSpecifier.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,14 +379,16 @@ public function specifyTypesInCondition(
379379
}
380380

381381
if (
382-
$rightType->isArray()->yes()
382+
!$context->null()
383+
&& $rightType->isArray()->yes()
383384
&& $leftType instanceof ConstantArrayType && $leftType->isEmpty()
384385
) {
385386
return $this->create($expr->right, new NonEmptyArrayType(), $context->negate(), false, $scope);
386387
}
387388

388389
if (
389-
$leftType->isArray()->yes()
390+
!$context->null()
391+
&& $leftType->isArray()->yes()
390392
&& $rightType instanceof ConstantArrayType && $rightType->isEmpty()
391393
) {
392394
return $this->create($expr->left, new NonEmptyArrayType(), $context->negate(), false, $scope);

tests/PHPStan/Analyser/AnalyserIntegrationTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,12 @@ public function testBug6896(): void
619619
$this->assertCount(6, $errors);
620620
}
621621

622+
public function testBug6940(): void
623+
{
624+
$errors = $this->runAnalyse(__DIR__ . '/data/bug-6940.php');
625+
$this->assertNoErrors($errors);
626+
}
627+
622628
/**
623629
* @param string[]|null $allAnalysedFiles
624630
* @return Error[]
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug6940;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
class Bug6940
8+
{
9+
10+
public function foo(): void
11+
{
12+
$b = [] == [];
13+
assertType('bool', $b);
14+
}
15+
16+
}

0 commit comments

Comments
 (0)