File tree Expand file tree Collapse file tree 2 files changed +42
-0
lines changed
tests/PHPStan/Analyser/nsrt Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -917,6 +917,18 @@ public function specifyTypesInCondition(
917917 && !$ scope ->getType ($ var ->var ) instanceof MixedType
918918 ) {
919919 $ dimType = $ scope ->getType ($ var ->dim );
920+ $ varType = $ scope ->getType ($ var ->var );
921+
922+ if ($ varType ->isArray ()->yes ()) {
923+ $ types = $ types ->unionWith (
924+ $ this ->create (
925+ $ var ->var ,
926+ new NonEmptyArrayType (),
927+ $ context ,
928+ $ scope ,
929+ )->setRootExpr ($ expr ),
930+ );
931+ }
920932
921933 if ($ dimType instanceof ConstantIntegerType || $ dimType instanceof ConstantStringType) {
922934 $ types = $ types ->unionWith (
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Bug13674a ;
4+
5+ use function assert ;
6+ use function PHPStan \Testing \assertType ;
7+
8+ class HelloWorld
9+ {
10+ /**
11+ * @param array<int> $arrayA
12+ * @param list<int> $listA
13+ */
14+ public function sayHello ($ arrayA , $ listA , int $ i ): void
15+ {
16+ if (isset ($ arrayA [$ i ])) {
17+ assertType ('non-empty-array<int> ' , $ arrayA );
18+ } else {
19+ assertType ('array<int> ' , $ arrayA );
20+ }
21+ assertType ('array<int> ' , $ arrayA );
22+
23+ if (isset ($ listA [$ i ])) {
24+ assertType ('non-empty-list<int> ' , $ listA );
25+ } else {
26+ assertType ('list<int> ' , $ listA );
27+ }
28+ assertType ('list<int> ' , $ listA );
29+ }
30+ }
You can’t perform that action at this time.
0 commit comments