@@ -576,43 +576,48 @@ public function specifyTypesInCondition(
576576 throw new ShouldNotHappenException ();
577577 }
578578
579- if ($ expr instanceof BooleanAnd && $ scope ->getType ($ expr ->left )->isTrue ()->yes ()) {
579+ if ($ context -> falsey () && $ scope ->getType ($ expr ->left )->isTrue ()->yes ()) {
580580 $ leftTypes = null ;
581581 } else {
582582 $ leftTypes = $ this ->specifyTypesInCondition ($ scope , $ expr ->left , $ context , $ rootExpr );
583583 }
584584
585585 $ rightScope = $ scope ->filterByTruthyValue ($ expr ->left );
586- if ($ expr instanceof BooleanAnd && $ rightScope ->getType ($ expr ->right )->isTrue ()->yes ()) {
586+ if ($ context -> falsey () && $ scope ->getType ($ expr ->right )->isTrue ()->yes ()) {
587587 $ rightTypes = null ;
588588 } else {
589589 $ rightTypes = $ this ->specifyTypesInCondition ($ rightScope , $ expr ->right , $ context , $ rootExpr );
590590 }
591591
592- if (null === $ leftTypes && null === $ rightTypes ) {
593- return new SpecifiedTypes ([], [], false , [], $ expr );
594- }
595- if (null === $ leftTypes ) {
596- return $ context ->true () ? $ rightTypes : $ rightTypes ->normalize ($ rightScope );
597- }
598- if (null === $ rightTypes ) {
599- return $ context ->true () ? $ leftTypes : $ leftTypes ->normalize ($ scope );
592+ if ($ leftTypes === null && $ rightTypes === null ) {
593+ $ types = new SpecifiedTypes ([], [], false , [], $ expr );
594+ } elseif ($ leftTypes === null ) {
595+ $ types = $ context ->true () ? $ rightTypes : $ rightTypes ->normalize ($ rightScope );
596+ } elseif ($ rightTypes === null ) {
597+ $ types = $ context ->true () ? $ leftTypes : $ leftTypes ->normalize ($ scope );
598+ } else {
599+ $ types = $ context ->true ()
600+ ? $ leftTypes ->unionWith ($ rightTypes )
601+ : $ leftTypes ->normalize ($ scope )->intersectWith ($ rightTypes ->normalize ($ rightScope ));
600602 }
601603
602- $ types = $ context ->true ()
603- ? $ leftTypes ->unionWith ($ rightTypes )
604- : $ leftTypes ->normalize ($ scope )->intersectWith ($ rightTypes ->normalize ($ rightScope ));
605604 if ($ context ->false ()) {
606- return new SpecifiedTypes (
607- $ types ->getSureTypes (),
608- $ types ->getSureNotTypes (),
609- false ,
610- array_merge (
605+ if ($ leftTypes === null || $ rightTypes === null ) {
606+ $ conditionalTypes = [];
607+ } else {
608+ $ conditionalTypes = array_merge (
611609 $ this ->processBooleanNotSureConditionalTypes ($ scope , $ leftTypes , $ rightTypes ),
612610 $ this ->processBooleanNotSureConditionalTypes ($ scope , $ rightTypes , $ leftTypes ),
613611 $ this ->processBooleanSureConditionalTypes ($ scope , $ leftTypes , $ rightTypes ),
614612 $ this ->processBooleanSureConditionalTypes ($ scope , $ rightTypes , $ leftTypes ),
615- ),
613+ );
614+ }
615+
616+ return new SpecifiedTypes (
617+ $ types ->getSureTypes (),
618+ $ types ->getSureNotTypes (),
619+ false ,
620+ $ conditionalTypes ,
616621 $ rootExpr ,
617622 );
618623 }
@@ -623,26 +628,26 @@ public function specifyTypesInCondition(
623628 throw new ShouldNotHappenException ();
624629 }
625630
626- if ($ expr instanceof BooleanOr && $ scope ->getType ($ expr ->left )->isFalse ()->yes ()) {
631+ if ($ context -> truthy () && $ scope ->getType ($ expr ->left )->isFalse ()->yes ()) {
627632 $ leftTypes = null ;
628633 } else {
629634 $ leftTypes = $ this ->specifyTypesInCondition ($ scope , $ expr ->left , $ context , $ rootExpr );
630635 }
631636
632637 $ rightScope = $ scope ->filterByFalseyValue ($ expr ->left );
633- if ($ expr instanceof BooleanOr && $ rightScope ->getType ($ expr ->right )->isFalse ()->yes ()) {
638+ if ($ context -> truthy () && $ scope ->getType ($ expr ->right )->isFalse ()->yes ()) {
634639 $ rightTypes = null ;
635640 } else {
636641 $ rightTypes = $ this ->specifyTypesInCondition ($ rightScope , $ expr ->right , $ context , $ rootExpr );
637642 }
638643
639- if (null === $ leftTypes && null === $ rightTypes ) {
644+ if ($ leftTypes === null && $ rightTypes === null ) {
640645 return new SpecifiedTypes ([], [], false , [], $ expr );
641646 }
642- if (null === $ leftTypes ) {
647+ if ($ leftTypes === null ) {
643648 return $ context ->true () ? $ rightTypes ->normalize ($ rightScope ) : $ rightTypes ;
644649 }
645- if (null === $ rightTypes ) {
650+ if ($ rightTypes === null ) {
646651 return $ context ->true () ? $ leftTypes ->normalize ($ scope ) : $ leftTypes ;
647652 }
648653
0 commit comments