Skip to content

Commit 03b5200

Browse files
committed
Attempt to fix hard-to-reproduce bug
1 parent 0c81ad9 commit 03b5200

1 file changed

Lines changed: 13 additions & 11 deletions

File tree

src/Analyser/MutatingScope.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3909,6 +3909,18 @@ public function mergeWith(?self $otherScope): self
39093909
$mergedExpressionTypes,
39103910
);
39113911

3912+
$filter = static function (ExpressionTypeHolder $expressionTypeHolder) {
3913+
if ($expressionTypeHolder->getCertainty()->yes()) {
3914+
return true;
3915+
}
3916+
3917+
$expr = $expressionTypeHolder->getExpr();
3918+
3919+
return $expr instanceof Variable || $expr instanceof VirtualNode;
3920+
};
3921+
3922+
$mergedExpressionTypes = array_filter($mergedExpressionTypes, $filter);
3923+
39123924
$ourNativeExpressionTypes = $this->nativeExpressionTypes;
39133925
$theirNativeExpressionTypes = $otherScope->nativeExpressionTypes;
39143926
$mergedNativeExpressionTypes = [];
@@ -3942,7 +3954,7 @@ public function mergeWith(?self $otherScope): self
39423954
$this->getFunction(),
39433955
$this->getNamespace(),
39443956
$mergedExpressionTypes,
3945-
array_merge($mergedNativeExpressionTypes, $this->mergeVariableHolders($ourNativeExpressionTypes, $theirNativeExpressionTypes)),
3957+
array_merge($mergedNativeExpressionTypes, array_filter($this->mergeVariableHolders($ourNativeExpressionTypes, $theirNativeExpressionTypes), $filter)),
39463958
$conditionalExpressions,
39473959
$this->inClosureBindScopeClasses,
39483960
$this->anonymousFunctionReflection,
@@ -4078,11 +4090,6 @@ private function mergeVariableHolders(array $ourVariableTypeHolders, array $thei
40784090
$intersectedVariableTypeHolders[$exprString] = $variableTypeHolder->and($theirVariableTypeHolders[$exprString]);
40794091
} else {
40804092
$expr = $variableTypeHolder->getExpr();
4081-
4082-
if (!$expr instanceof Variable && !$expr instanceof VirtualNode) {
4083-
continue;
4084-
}
4085-
40864093
if (!$expr->hasAttribute(self::CONTAINS_SUPER_GLOBAL_ATTRIBUTE_NAME)) {
40874094
$expr->setAttribute(self::CONTAINS_SUPER_GLOBAL_ATTRIBUTE_NAME, $nodeFinder->findFirst($expr, $globalVariableCallback) !== null);
40884095
}
@@ -4100,11 +4107,6 @@ private function mergeVariableHolders(array $ourVariableTypeHolders, array $thei
41004107
}
41014108

41024109
$expr = $variableTypeHolder->getExpr();
4103-
4104-
if (!$expr instanceof Variable && !$expr instanceof VirtualNode) {
4105-
continue;
4106-
}
4107-
41084110
if (!$expr->hasAttribute(self::CONTAINS_SUPER_GLOBAL_ATTRIBUTE_NAME)) {
41094111
$expr->setAttribute(self::CONTAINS_SUPER_GLOBAL_ATTRIBUTE_NAME, $nodeFinder->findFirst($expr, $globalVariableCallback) !== null);
41104112
}

0 commit comments

Comments
 (0)