Skip to content

Commit

Permalink
try fixing missing default context asserts
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm committed Jun 12, 2024
1 parent 5f097a7 commit f87be07
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/Analyser/TypeSpecifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ public function specifyTypesInCondition(
$parametersAcceptor instanceof ParametersAcceptorWithPhpDocs ? $parametersAcceptor->getCallSiteVarianceMap() : TemplateTypeVarianceMap::createEmpty(),
TemplateTypeVariance::createInvariant(),
));
$specifiedTypes = $this->specifyTypesFromAsserts($context, $expr, $asserts, $parametersAcceptor, $scope);
$specifiedTypes = $this->specifyTypesFromAsserts($context, $rootExpr, $expr, $asserts, $parametersAcceptor, $scope);
if ($specifiedTypes !== null) {
return $specifiedTypes;
}
Expand Down Expand Up @@ -510,7 +510,7 @@ public function specifyTypesInCondition(
$parametersAcceptor instanceof ParametersAcceptorWithPhpDocs ? $parametersAcceptor->getCallSiteVarianceMap() : TemplateTypeVarianceMap::createEmpty(),
TemplateTypeVariance::createInvariant(),
));
$specifiedTypes = $this->specifyTypesFromAsserts($context, $expr, $asserts, $parametersAcceptor, $scope);
$specifiedTypes = $this->specifyTypesFromAsserts($context, $rootExpr, $expr, $asserts, $parametersAcceptor, $scope);
if ($specifiedTypes !== null) {
return $specifiedTypes;
}
Expand Down Expand Up @@ -563,7 +563,7 @@ public function specifyTypesInCondition(
$parametersAcceptor instanceof ParametersAcceptorWithPhpDocs ? $parametersAcceptor->getCallSiteVarianceMap() : TemplateTypeVarianceMap::createEmpty(),
TemplateTypeVariance::createInvariant(),
));
$specifiedTypes = $this->specifyTypesFromAsserts($context, $expr, $asserts, $parametersAcceptor, $scope);
$specifiedTypes = $this->specifyTypesFromAsserts($context, $rootExpr, $expr, $asserts, $parametersAcceptor, $scope);
if ($specifiedTypes !== null) {
return $specifiedTypes;
}
Expand Down Expand Up @@ -922,7 +922,7 @@ public function specifyTypesInCondition(
TemplateTypeVariance::createInvariant(),
));

$specifiedTypes = $this->specifyTypesFromAsserts($context, $expr, $asserts, $parametersAcceptor, $scope);
$specifiedTypes = $this->specifyTypesFromAsserts($context, $rootExpr, $expr, $asserts, $parametersAcceptor, $scope);

if ($specifiedTypes !== null) {
return $specifiedTypes;
Expand Down Expand Up @@ -1293,7 +1293,7 @@ public function getConditionalSpecifiedTypes(
return $specifiedTypes;
}

private function specifyTypesFromAsserts(TypeSpecifierContext $context, Expr\CallLike $call, Assertions $assertions, ParametersAcceptor $parametersAcceptor, Scope $scope): ?SpecifiedTypes
private function specifyTypesFromAsserts(TypeSpecifierContext $context, ?Expr $rootExpr, Expr\CallLike $call, Assertions $assertions, ParametersAcceptor $parametersAcceptor, Scope $scope): ?SpecifiedTypes
{
if ($context->null()) {
$asserts = $assertions->getAsserts();
Expand Down Expand Up @@ -1334,8 +1334,7 @@ private function specifyTypesFromAsserts(TypeSpecifierContext $context, Expr\Cal
$argsMap['this'] = [$call->var];
}

/** @var SpecifiedTypes|null $types */
$types = null;
$types = $this->handleDefaultTruthyOrFalseyContext($context, $rootExpr, $call, $scope);

foreach ($asserts as $assert) {
foreach ($argsMap[substr($assert->getParameter()->getParameterName(), 1)] ?? [] as $parameterExpr) {
Expand Down Expand Up @@ -1378,7 +1377,7 @@ static function (Type $type, callable $traverse) use ($templateTypeMap, &$contai
$scope,
$containsUnresolvedTemplate || $assert->isEquality() ? $call : null,
);
$types = $types !== null ? $types->unionWith($newTypes) : $newTypes;
$types = $types->unionWith($newTypes);

if (!$context->null() || !$assertedType instanceof ConstantBooleanType) {
continue;
Expand Down

0 comments on commit f87be07

Please sign in to comment.