@@ -3210,6 +3210,7 @@ public function filterBySpecifiedTypes(SpecifiedTypes $specifiedTypes): self
32103210
32113211 $ conditions = [];
32123212 $ prevSpecifiedCount = -1 ;
3213+ $ debugFile = getenv ('PHPSTAN_DEBUG_FILTER ' ) ?: '' ;
32133214 while (count ($ specifiedExpressions ) !== $ prevSpecifiedCount ) {
32143215 $ prevSpecifiedCount = count ($ specifiedExpressions );
32153216 foreach ($ scope ->conditionalExpressions as $ conditionalExprString => $ conditionalExpressions ) {
@@ -3218,11 +3219,31 @@ public function filterBySpecifiedTypes(SpecifiedTypes $specifiedTypes): self
32183219 }
32193220 foreach ($ conditionalExpressions as $ conditionalExpression ) {
32203221 foreach ($ conditionalExpression ->getConditionExpressionTypeHolders () as $ holderExprString => $ conditionalTypeHolder ) {
3221- if (!array_key_exists ($ holderExprString , $ specifiedExpressions ) || ! $ specifiedExpressions [ $ holderExprString ]-> equals ( $ conditionalTypeHolder ) ) {
3222+ if (!array_key_exists ($ holderExprString , $ specifiedExpressions )) {
32223223 continue 2 ;
32233224 }
3225+ $ specifiedHolder = $ specifiedExpressions [$ holderExprString ];
3226+ if (!$ specifiedHolder ->equals ($ conditionalTypeHolder )) {
3227+ if (
3228+ !$ conditionalExpression ->getTypeHolder ()->getCertainty ()->yes ()
3229+ || !$ specifiedHolder ->getCertainty ()->equals ($ conditionalTypeHolder ->getCertainty ())
3230+ || !$ conditionalTypeHolder ->getType () instanceof UnionType
3231+ || !$ conditionalTypeHolder ->getType ()->isSuperTypeOf ($ specifiedHolder ->getType ())->yes ()
3232+ ) {
3233+ if ($ debugFile !== '' && str_contains ($ scope ->getFile (), $ debugFile )) {
3234+ file_put_contents ('/tmp/phpstan-debug.log ' , sprintf ("SKIP: target=%s guard=%s guardType=%s specType=%s targetCert=%s \n" , $ conditionalExprString , $ holderExprString , $ conditionalTypeHolder ->getType ()->describe (\PHPStan \Type \VerbosityLevel::precise ()), $ specifiedHolder ->getType ()->describe (\PHPStan \Type \VerbosityLevel::precise ()), $ conditionalExpression ->getTypeHolder ()->getCertainty ()->describe ()), FILE_APPEND );
3235+ }
3236+ continue 2 ;
3237+ }
3238+ if ($ debugFile !== '' && str_contains ($ scope ->getFile (), $ debugFile )) {
3239+ file_put_contents ('/tmp/phpstan-debug.log ' , sprintf ("RELAXED MATCH: target=%s guard=%s guardType=%s specType=%s targetCert=%s targetType=%s \n" , $ conditionalExprString , $ holderExprString , $ conditionalTypeHolder ->getType ()->describe (\PHPStan \Type \VerbosityLevel::precise ()), $ specifiedHolder ->getType ()->describe (\PHPStan \Type \VerbosityLevel::precise ()), $ conditionalExpression ->getTypeHolder ()->getCertainty ()->describe (), $ conditionalExpression ->getTypeHolder ()->getType ()->describe (\PHPStan \Type \VerbosityLevel::precise ())), FILE_APPEND );
3240+ }
3241+ }
32243242 }
32253243
3244+ if ($ debugFile !== '' && str_contains ($ scope ->getFile (), $ debugFile )) {
3245+ file_put_contents ('/tmp/phpstan-debug.log ' , sprintf ("MATCHED: target=%s targetType=%s targetCert=%s \n" , $ conditionalExprString , $ conditionalExpression ->getTypeHolder ()->getType ()->describe (\PHPStan \Type \VerbosityLevel::precise ()), $ conditionalExpression ->getTypeHolder ()->getCertainty ()->describe ()), FILE_APPEND );
3246+ }
32263247 $ conditions [$ conditionalExprString ][] = $ conditionalExpression ;
32273248 $ specifiedExpressions [$ conditionalExprString ] = $ conditionalExpression ->getTypeHolder ();
32283249 }
0 commit comments