File tree Expand file tree Collapse file tree 2 files changed +27
-1
lines changed
tests/PHPStan/Analyser/nsrt Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -663,7 +663,17 @@ public function specifyTypesInCondition(
663663 $ leftTypes = $ this ->specifyTypesInCondition ($ scope , $ expr ->left , $ context )->setRootExpr ($ expr );
664664 $ rightScope = $ scope ->filterByFalseyValue ($ expr ->left );
665665 $ rightTypes = $ this ->specifyTypesInCondition ($ rightScope , $ expr ->right , $ context )->setRootExpr ($ expr );
666- $ types = $ context ->true () ? $ leftTypes ->normalize ($ scope )->intersectWith ($ rightTypes ->normalize ($ rightScope )) : $ leftTypes ->unionWith ($ rightTypes );
666+
667+ if ($ context ->true ()) {
668+ if ($ scope ->getType ($ expr ->left )->isFalse ()->yes ()) {
669+ $ types = $ rightTypes ->normalize ($ rightScope );
670+ } else {
671+ $ types = $ leftTypes ->normalize ($ scope )->intersectWith ($ rightTypes ->normalize ($ rightScope ));
672+ }
673+ } else {
674+ $ types = $ leftTypes ->unionWith ($ rightTypes );
675+ }
676+
667677 if ($ context ->true ()) {
668678 return (new SpecifiedTypes (
669679 $ types ->getSureTypes (),
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ use function PHPStan \Testing \assertType ;
4+
5+ function sayEqualArrayShape (int $ i , $ arr ): void
6+ {
7+ if (
8+ false || array_key_exists ($ i , $ arr )
9+ ) {
10+ assertType ('non-empty-array ' , $ arr );
11+ }
12+
13+ if (array_key_exists ($ i , $ arr )) {
14+ assertType ('non-empty-array ' , $ arr );
15+ }
16+ }
You can’t perform that action at this time.
0 commit comments