@@ -3614,7 +3614,7 @@ private function enterArrowFunctionWithoutReflection(Expr\ArrowFunction $arrowFu
36143614 if (!$ parameter ->var instanceof Variable || !is_string ($ parameter ->var ->name )) {
36153615 throw new ShouldNotHappenException ();
36163616 }
3617- $ arrowFunctionScope = $ arrowFunctionScope ->assignVariable ($ parameter ->var ->name , $ parameterType , $ parameterType );
3617+ $ arrowFunctionScope = $ arrowFunctionScope ->assignVariable ($ parameter ->var ->name , $ parameterType , $ parameterType, TrinaryLogic:: createYes () );
36183618 }
36193619
36203620 if ($ arrowFunction ->static ) {
@@ -3733,6 +3733,7 @@ public function enterForeach(self $originalScope, Expr $iteratee, string $valueN
37333733 $ valueName ,
37343734 $ originalScope ->getIterableValueType ($ iterateeType ),
37353735 $ originalScope ->getIterableValueType ($ nativeIterateeType ),
3736+ TrinaryLogic::createYes (),
37363737 );
37373738 if ($ keyName !== null ) {
37383739 $ scope = $ scope ->enterForeachKey ($ originalScope , $ iteratee , $ keyName );
@@ -3749,6 +3750,7 @@ public function enterForeachKey(self $originalScope, Expr $iteratee, string $key
37493750 $ keyName ,
37503751 $ originalScope ->getIterableKeyType ($ iterateeType ),
37513752 $ originalScope ->getIterableKeyType ($ nativeIterateeType ),
3753+ TrinaryLogic::createYes (),
37523754 );
37533755
37543756 if ($ iterateeType ->isArray ()->yes ()) {
@@ -3783,6 +3785,7 @@ public function enterCatchType(Type $catchType, ?string $variableName): self
37833785 $ variableName ,
37843786 TypeCombinator::intersect ($ catchType , new ObjectType (Throwable::class)),
37853787 TypeCombinator::intersect ($ catchType , new ObjectType (Throwable::class)),
3788+ TrinaryLogic::createYes (),
37863789 );
37873790 }
37883791
@@ -3928,18 +3931,16 @@ public function isUndefinedExpressionAllowed(Expr $expr): bool
39283931 return array_key_exists ($ exprString , $ this ->currentlyAllowedUndefinedExpressions );
39293932 }
39303933
3931- public function assignVariable (string $ variableName , Type $ type , Type $ nativeType , ? TrinaryLogic $ certainty = null ): self
3934+ public function assignVariable (string $ variableName , Type $ type , Type $ nativeType , TrinaryLogic $ certainty ): self
39323935 {
39333936 $ node = new Variable ($ variableName );
39343937 $ scope = $ this ->assignExpression ($ node , $ type , $ nativeType );
3935- if ($ certainty !== null ) {
3936- if ($ certainty ->no ()) {
3937- throw new ShouldNotHappenException ();
3938- } elseif (!$ certainty ->yes ()) {
3939- $ exprString = '$ ' . $ variableName ;
3940- $ scope ->expressionTypes [$ exprString ] = new ExpressionTypeHolder ($ node , $ type , $ certainty );
3941- $ scope ->nativeExpressionTypes [$ exprString ] = new ExpressionTypeHolder ($ node , $ nativeType , $ certainty );
3942- }
3938+ if ($ certainty ->no ()) {
3939+ throw new ShouldNotHappenException ();
3940+ } elseif (!$ certainty ->yes ()) {
3941+ $ exprString = '$ ' . $ variableName ;
3942+ $ scope ->expressionTypes [$ exprString ] = new ExpressionTypeHolder ($ node , $ type , $ certainty );
3943+ $ scope ->nativeExpressionTypes [$ exprString ] = new ExpressionTypeHolder ($ node , $ nativeType , $ certainty );
39433944 }
39443945
39453946 $ parameterOriginalValueExprString = $ this ->getNodeKey (new ParameterVariableOriginalValueExpr ($ variableName ));
@@ -3987,7 +3988,7 @@ public function unsetExpression(Expr $expr): self
39873988 return $ scope ->invalidateExpression ($ expr );
39883989 }
39893990
3990- public function specifyExpressionType (Expr $ expr , Type $ type , Type $ nativeType , ? TrinaryLogic $ certainty = null ): self
3991+ public function specifyExpressionType (Expr $ expr , Type $ type , Type $ nativeType , TrinaryLogic $ certainty ): self
39913992 {
39923993 if ($ expr instanceof ConstFetch) {
39933994 $ loweredConstName = strtolower ($ expr ->name ->toString ());
@@ -4035,9 +4036,7 @@ public function specifyExpressionType(Expr $expr, Type $type, Type $nativeType,
40354036 }
40364037 }
40374038
4038- if ($ certainty === null ) {
4039- $ certainty = TrinaryLogic::createYes ();
4040- } elseif ($ certainty ->no ()) {
4039+ if ($ certainty ->no ()) {
40414040 throw new ShouldNotHappenException ();
40424041 }
40434042
@@ -4073,11 +4072,8 @@ public function specifyExpressionType(Expr $expr, Type $type, Type $nativeType,
40734072 return $ scope ;
40744073 }
40754074
4076- public function assignExpression (Expr $ expr , Type $ type , ? Type $ nativeType = null ): self
4075+ public function assignExpression (Expr $ expr , Type $ type , Type $ nativeType ): self
40774076 {
4078- if ($ nativeType === null ) {
4079- $ nativeType = new MixedType ();
4080- }
40814077 $ scope = $ this ;
40824078 if ($ expr instanceof PropertyFetch) {
40834079 $ scope = $ this ->invalidateExpression ($ expr )
@@ -4088,7 +4084,7 @@ public function assignExpression(Expr $expr, Type $type, ?Type $nativeType = nul
40884084 $ scope = $ this ->invalidateExpression ($ expr );
40894085 }
40904086
4091- return $ scope ->specifyExpressionType ($ expr , $ type , $ nativeType );
4087+ return $ scope ->specifyExpressionType ($ expr , $ type , $ nativeType, TrinaryLogic:: createYes () );
40924088 }
40934089
40944090 public function assignInitializedProperty (Type $ fetchedOnType , string $ propertyName ): self
@@ -4292,13 +4288,14 @@ public function addTypeToExpression(Expr $expr, Type $type): self
42924288
42934289 if ($ originalExprType ->equals ($ nativeType )) {
42944290 $ newType = TypeCombinator::intersect ($ type , $ originalExprType );
4295- return $ this ->specifyExpressionType ($ expr , $ newType , $ newType );
4291+ return $ this ->specifyExpressionType ($ expr , $ newType , $ newType, TrinaryLogic:: createYes () );
42964292 }
42974293
42984294 return $ this ->specifyExpressionType (
42994295 $ expr ,
43004296 TypeCombinator::intersect ($ type , $ originalExprType ),
43014297 TypeCombinator::intersect ($ type , $ nativeType ),
4298+ TrinaryLogic::createYes (),
43024299 );
43034300 }
43044301
@@ -4315,6 +4312,7 @@ public function removeTypeFromExpression(Expr $expr, Type $typeToRemove): self
43154312 $ expr ,
43164313 TypeCombinator::remove ($ exprType , $ typeToRemove ),
43174314 TypeCombinator::remove ($ this ->getNativeType ($ expr ), $ typeToRemove ),
4315+ TrinaryLogic::createYes (),
43184316 );
43194317 }
43204318
0 commit comments