@@ -1040,36 +1040,11 @@ private function specifyTypesForConstantBinaryExpression(
1040
1040
) {
1041
1041
$ argType = $ scope ->getType ($ exprNode ->getArgs ()[0 ]->value );
1042
1042
1043
- if (count ($ exprNode ->getArgs ()) === 1 ) {
1044
- $ isNormalCount = TrinaryLogic::createYes ();
1045
- } else {
1046
- $ mode = $ scope ->getType ($ exprNode ->getArgs ()[1 ]->value );
1047
- $ isNormalCount = (new ConstantIntegerType (COUNT_NORMAL ))->isSuperTypeOf ($ mode )->or ($ argType ->getIterableValueType ()->isArray ()->negate ());
1048
- }
1049
-
1050
- if (
1051
- $ isNormalCount ->yes ()
1052
- && $ argType instanceof UnionType
1053
- ) {
1054
- $ result = [];
1055
- foreach ($ argType ->getTypes () as $ innerType ) {
1056
- $ arraySize = $ innerType ->getArraySize ();
1057
- $ isSize = $ constantType ->isSuperTypeOf ($ arraySize );
1058
- if ($ context ->truthy ()) {
1059
- if ($ isSize ->no ()) {
1060
- continue ;
1061
- }
1062
- }
1063
- if ($ context ->falsey ()) {
1064
- if (!$ isSize ->yes ()) {
1065
- continue ;
1066
- }
1067
- }
1068
-
1069
- $ result [] = $ innerType ;
1043
+ if ($ argType instanceof UnionType) {
1044
+ $ narrowed = $ this ->narrowUnionBySize ($ exprNode , $ argType , $ constantType , $ context , $ scope , $ rootExpr );
1045
+ if ($ narrowed !== null ) {
1046
+ return $ narrowed ;
1070
1047
}
1071
-
1072
- return $ this ->create ($ exprNode ->getArgs ()[0 ]->value , TypeCombinator::union (...$ result ), $ context , false , $ scope , $ rootExpr );
1073
1048
}
1074
1049
1075
1050
if ($ context ->truthy () || $ constantType ->getValue () === 0 ) {
@@ -1079,6 +1054,13 @@ private function specifyTypesForConstantBinaryExpression(
1079
1054
}
1080
1055
1081
1056
if ($ argType ->isArray ()->yes ()) {
1057
+ if (count ($ exprNode ->getArgs ()) === 1 ) {
1058
+ $ isNormalCount = TrinaryLogic::createYes ();
1059
+ } else {
1060
+ $ mode = $ scope ->getType ($ exprNode ->getArgs ()[1 ]->value );
1061
+ $ isNormalCount = (new ConstantIntegerType (COUNT_NORMAL ))->isSuperTypeOf ($ mode )->or ($ argType ->getIterableValueType ()->isArray ()->negate ());
1062
+ }
1063
+
1082
1064
$ funcTypes = $ this ->create ($ exprNode , $ constantType , $ context , false , $ scope , $ rootExpr );
1083
1065
if ($ isNormalCount ->yes () && $ argType ->isList ()->yes () && $ context ->truthy () && $ constantType ->getValue () < ConstantArrayTypeBuilder::ARRAY_COUNT_LIMIT ) {
1084
1066
$ valueTypesBuilder = ConstantArrayTypeBuilder::createEmpty ();
0 commit comments