File tree Expand file tree Collapse file tree 2 files changed +17
-3
lines changed
tests/PHPStan/Analyser/nsrt Expand file tree Collapse file tree 2 files changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -1061,10 +1061,11 @@ private function specifyTypesForCountFuncCall(
1061
1061
$ isNormalCount = (new ConstantIntegerType (COUNT_NORMAL ))->isSuperTypeOf ($ mode )->result ->or ($ type ->getIterableValueType ()->isArray ()->negate ());
1062
1062
}
1063
1063
1064
+ $ isConstantArray = $ type ->isConstantArray ();
1064
1065
$ isList = $ type ->isList ();
1065
1066
if (
1066
1067
!$ isNormalCount ->yes ()
1067
- || (!$ type -> isConstantArray () ->yes () && !$ isList ->yes ())
1068
+ || (!$ isConstantArray ->yes () && !$ isList ->yes ())
1068
1069
|| $ type ->isIterableAtLeastOnce ()->no () // array{} cannot be used for further narrowing
1069
1070
) {
1070
1071
return null ;
@@ -1082,9 +1083,12 @@ private function specifyTypesForCountFuncCall(
1082
1083
}
1083
1084
1084
1085
if (
1085
- $ isList ->yes ()
1086
- && $ sizeType instanceof ConstantIntegerType
1086
+ $ sizeType instanceof ConstantIntegerType
1087
1087
&& $ sizeType ->getValue () < ConstantArrayTypeBuilder::ARRAY_COUNT_LIMIT
1088
+ && (
1089
+ $ isList ->yes ()
1090
+ || $ isConstantArray ->yes () && $ arrayType ->getKeyType ()->isSuperTypeOf (IntegerRangeType::fromInterval (0 , $ sizeType ->getValue () - 1 ))->yes ()
1091
+ )
1088
1092
) {
1089
1093
// turn optional offsets non-optional
1090
1094
$ valueTypesBuilder = ConstantArrayTypeBuilder::createEmpty ();
Original file line number Diff line number Diff line change @@ -87,6 +87,16 @@ public function doBaz(array $arr): void
87
87
assertType ('1|2 ' , count ($ arr ));
88
88
}
89
89
90
+ public function constantArrayWhichCanBecomeList (string $ h ): void
91
+ {
92
+ preg_match ('#^([a-z0-9-]+)\..+$# ' , $ h , $ matches );
93
+ if (count ($ matches ) !== 2 ) {
94
+ return ;
95
+ }
96
+
97
+ assertType ('array{string, non-empty-string} ' , $ matches );
98
+ }
99
+
90
100
}
91
101
92
102
/**
You can’t perform that action at this time.
0 commit comments