Skip to content

Commit

Permalink
make $conditionalExpressions key consistent in all usages
Browse files Browse the repository at this point in the history
  • Loading branch information
rajyan authored and ondrejmirtes committed May 2, 2022
1 parent 55b9952 commit 1e95392
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
9 changes: 6 additions & 3 deletions src/Analyser/NodeScopeResolver.php
Expand Up @@ -3490,11 +3490,12 @@ private function processSureTypesForConditionalExpressionsAfterAssign(Scope $sco
$conditionalExpressions[$exprString] = [];
}

$conditionalExpressions[$exprString][] = new ConditionalExpressionHolder([
$holder = new ConditionalExpressionHolder([
'$' . $variableName => $variableType,
], VariableTypeHolder::createYes(
TypeCombinator::intersect($scope->getType($expr), $exprType),
));
$conditionalExpressions[$exprString][$holder->getKey()] = $holder;
}

return $conditionalExpressions;
Expand All @@ -3518,11 +3519,12 @@ private function processSureNotTypesForConditionalExpressionsAfterAssign(Scope $
$conditionalExpressions[$exprString] = [];
}

$conditionalExpressions[$exprString][] = new ConditionalExpressionHolder([
$holder = new ConditionalExpressionHolder([
'$' . $variableName => $variableType,
], VariableTypeHolder::createYes(
TypeCombinator::remove($scope->getType($expr), $exprType),
));
$conditionalExpressions[$exprString][$holder->getKey()] = $holder;
}

return $conditionalExpressions;
Expand Down Expand Up @@ -3689,9 +3691,10 @@ static function (): void {
$conditionalHolders = [];
foreach ($iterateeType->getKeyTypes() as $i => $keyType) {
$valueType = $iterateeType->getValueTypes()[$i];
$conditionalHolders[] = new ConditionalExpressionHolder([
$holder = new ConditionalExpressionHolder([
'$' . $stmt->keyVar->name => $keyType,
], new VariableTypeHolder($valueType, TrinaryLogic::createYes()));
$conditionalHolders[$holder->getKey()] = $holder;
}

$scope = $scope->addConditionalExpressions(
Expand Down
3 changes: 2 additions & 1 deletion src/Analyser/TypeSpecifier.php
Expand Up @@ -962,10 +962,11 @@ private function processBooleanConditionalTypes(Scope $scope, SpecifiedTypes $le
$holders[$exprString] = [];
}

$holders[$exprString][] = new ConditionalExpressionHolder(
$holder = new ConditionalExpressionHolder(
$conditionExpressionTypes,
new VariableTypeHolder(TypeCombinator::remove($scope->getType($expr), $type), TrinaryLogic::createYes()),
);
$holders[$exprString][$holder->getKey()] = $holder;
}

return $holders;
Expand Down

0 comments on commit 1e95392

Please sign in to comment.