Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions src/Analyser/ExprHandler/Helper/NonNullabilityHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use PHPStan\DependencyInjection\AutowiredService;
use PHPStan\TrinaryLogic;
use PHPStan\Type\TypeCombinator;
use function array_unshift;

#[AutowiredService]
final class NonNullabilityHelper
Expand Down Expand Up @@ -49,11 +48,7 @@ public function ensureShallowNonNullability(MutatingScope $scope, Scope $origina
return new EnsuredNonNullabilityResult($scope, []);
}

$nativeType = $scope->getNativeType($exprToSpecify);

$specifiedExpressions = [
new EnsuredNonNullabilityResultExpression($exprToSpecify, $exprType, $nativeType, $certainty),
];
$specifiedExpressions = [];

// When narrowing an ArrayDimFetch, specifyExpressionType also recursively
// narrows the parent array's offset type via intersection with HasOffsetValueType.
Expand All @@ -65,14 +60,16 @@ public function ensureShallowNonNullability(MutatingScope $scope, Scope $origina
if (!$hasParentExpressionType->no()) {
$parentCertainty = $hasParentExpressionType;
}
array_unshift($specifiedExpressions, new EnsuredNonNullabilityResultExpression(
$specifiedExpressions[] = new EnsuredNonNullabilityResultExpression(
$parentExpr,
$scope->getType($parentExpr),
$scope->getNativeType($parentExpr),
$parentCertainty,
));
);
}

$nativeType = $scope->getNativeType($exprToSpecify);
$specifiedExpressions[] = new EnsuredNonNullabilityResultExpression($exprToSpecify, $exprType, $nativeType, $certainty);
$scope = $scope->specifyExpressionType(
$exprToSpecify,
$exprTypeWithoutNull,
Expand Down
Loading