1515use PHPStan \DependencyInjection \AutowiredService ;
1616use PHPStan \TrinaryLogic ;
1717use PHPStan \Type \TypeCombinator ;
18- use function array_unshift ;
1918
2019#[AutowiredService]
2120final class NonNullabilityHelper
@@ -49,11 +48,7 @@ public function ensureShallowNonNullability(MutatingScope $scope, Scope $origina
4948 return new EnsuredNonNullabilityResult ($ scope , []);
5049 }
5150
52- $ nativeType = $ scope ->getNativeType ($ exprToSpecify );
53-
54- $ specifiedExpressions = [
55- new EnsuredNonNullabilityResultExpression ($ exprToSpecify , $ exprType , $ nativeType , $ certainty ),
56- ];
51+ $ specifiedExpressions = [];
5752
5853 // When narrowing an ArrayDimFetch, specifyExpressionType also recursively
5954 // narrows the parent array's offset type via intersection with HasOffsetValueType.
@@ -65,14 +60,16 @@ public function ensureShallowNonNullability(MutatingScope $scope, Scope $origina
6560 if (!$ hasParentExpressionType ->no ()) {
6661 $ parentCertainty = $ hasParentExpressionType ;
6762 }
68- array_unshift ( $ specifiedExpressions, new EnsuredNonNullabilityResultExpression (
63+ $ specifiedExpressions[] = new EnsuredNonNullabilityResultExpression (
6964 $ parentExpr ,
7065 $ scope ->getType ($ parentExpr ),
7166 $ scope ->getNativeType ($ parentExpr ),
7267 $ parentCertainty ,
73- )) ;
68+ );
7469 }
7570
71+ $ nativeType = $ scope ->getNativeType ($ exprToSpecify );
72+ $ specifiedExpressions [] = new EnsuredNonNullabilityResultExpression ($ exprToSpecify , $ exprType , $ nativeType , $ certainty );
7673 $ scope = $ scope ->specifyExpressionType (
7774 $ exprToSpecify ,
7875 $ exprTypeWithoutNull ,
0 commit comments