Skip to content

Commit

Permalink
Do not call TypeSpecifier::specifyTypesInCondition with a non-null co…
Browse files Browse the repository at this point in the history
…ntext in case the original context is null
  • Loading branch information
herndlm committed May 3, 2022
1 parent 1e95392 commit 50f90e7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Analyser/TypeSpecifier.php
Expand Up @@ -175,7 +175,7 @@ public function specifyTypesInCondition(
$exprNode = $expressions[0];
/** @var ConstantScalarType $constantType */
$constantType = $expressions[1];
if ($constantType->getValue() === false) {
if (!$context->null() && $constantType->getValue() === false) {
$types = $this->create($exprNode, $constantType, $context, false, $scope, $rootExpr);
return $types->unionWith($this->specifyTypesInCondition(
$scope,
Expand All @@ -185,7 +185,7 @@ public function specifyTypesInCondition(
));
}

if ($constantType->getValue() === true) {
if (!$context->null() && $constantType->getValue() === true) {
$types = $this->create($exprNode, $constantType, $context, false, $scope, $rootExpr);
return $types->unionWith($this->specifyTypesInCondition(
$scope,
Expand Down Expand Up @@ -339,7 +339,7 @@ public function specifyTypesInCondition(
$exprNode = $expressions[0];
/** @var ConstantScalarType $constantType */
$constantType = $expressions[1];
if ($constantType->getValue() === false || $constantType->getValue() === null) {
if (!$context->null() && ($constantType->getValue() === false || $constantType->getValue() === null)) {
return $this->specifyTypesInCondition(
$scope,
$exprNode,
Expand All @@ -348,7 +348,7 @@ public function specifyTypesInCondition(
);
}

if ($constantType->getValue() === true) {
if (!$context->null() && $constantType->getValue() === true) {
return $this->specifyTypesInCondition(
$scope,
$exprNode,
Expand Down
Expand Up @@ -528,4 +528,10 @@ public function testBug6939(): void
]);
}

public function testBug7166(): void
{
$this->checkAlwaysTrueStrictComparison = true;
$this->analyse([__DIR__ . '/data/bug-7166.php'], []);
}

}

0 comments on commit 50f90e7

Please sign in to comment.