@@ -717,11 +717,14 @@ public function specifyTypesInCondition(
717717
718718 $ types = null ;
719719 foreach ($ vars as $ var ) {
720+ $ type = new SpecifiedTypes ();
721+ 720722 if ($ var instanceof Expr \Variable && is_string ($ var ->name )) {
721723 if ($ scope ->hasVariableType ($ var ->name )->no ()) {
722724 return new SpecifiedTypes ([], [], false , [], $ rootExpr );
723725 }
724726 }
727+ 725728 if (
726729 $ var instanceof ArrayDimFetch
727730 && $ var ->dim !== null
@@ -738,36 +741,32 @@ public function specifyTypesInCondition(
738741 $ scope ,
739742 $ rootExpr ,
740743 );
741- } else {
742- $ type = new SpecifiedTypes ();
743744 }
744- 745- $ type = $ type ->unionWith (
746- $ this ->create ($ var , new NullType (), TypeSpecifierContext::createFalse (), false , $ scope , $ rootExpr ),
747- );
748- } else {
749- $ type = $ this ->create ($ var , new NullType (), TypeSpecifierContext::createFalse (), false , $ scope , $ rootExpr );
750745 }
751746
752747 if (
753748 $ var instanceof PropertyFetch
754749 && $ var ->name instanceof Node \Identifier
755750 ) {
756- $ type = $ type -> unionWith ( $ this ->create ($ var ->var , new IntersectionType ([
751+ $ type = $ this ->create ($ var ->var , new IntersectionType ([
757752 new ObjectWithoutClassType (),
758753 new HasPropertyType ($ var ->name ->toString ()),
759- ]), TypeSpecifierContext::createTruthy (), false , $ scope , $ rootExpr )) ;
754+ ]), TypeSpecifierContext::createTruthy (), false , $ scope , $ rootExpr );
760755 } elseif (
761756 $ var instanceof StaticPropertyFetch
762757 && $ var ->class instanceof Expr
763758 && $ var ->name instanceof Node \VarLikeIdentifier
764759 ) {
765- $ type = $ type -> unionWith ( $ this ->create ($ var ->class , new IntersectionType ([
760+ $ type = $ this ->create ($ var ->class , new IntersectionType ([
766761 new ObjectWithoutClassType (),
767762 new HasPropertyType ($ var ->name ->toString ()),
768- ]), TypeSpecifierContext::createTruthy (), false , $ scope , $ rootExpr )) ;
763+ ]), TypeSpecifierContext::createTruthy (), false , $ scope , $ rootExpr );
769764 }
770765
766+ $ type = $ type ->unionWith (
767+ $ this ->create ($ var , new NullType (), TypeSpecifierContext::createFalse (), false , $ scope , $ rootExpr ),
768+ );
769+ 771770 if ($ types === null ) {
772771 $ types = $ type ;
773772 } else {
@@ -792,6 +791,15 @@ public function specifyTypesInCondition(
792791 } elseif (
793792 $ expr instanceof Expr \Empty_
794793 ) {
794+ if (!$ scope instanceof MutatingScope) {
795+ throw new ShouldNotHappenException ();
796+ }
797+ 798+ $ isset = $ scope ->issetCheck ($ expr ->expr , static fn () => true );
799+ if ($ isset === false ) {
800+ return new SpecifiedTypes ();
801+ }
802+ 795803 return $ this ->specifyTypesInCondition ($ scope , new BooleanOr (
796804 new Expr \BooleanNot (new Expr \Isset_ ([$ expr ->expr ])),
797805 new Expr \BooleanNot ($ expr ->expr ),
0 commit comments