-
Notifications
You must be signed in to change notification settings - Fork 506
Narrow array on count() with positive-int #3389
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
assertType('non-empty-array', $arr); | ||
assertType('array', $arr); | ||
} | ||
if (count($arr) === $maybeZero) { | ||
assertType('array', $arr); | ||
} else { | ||
assertType('non-empty-array', $arr); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I did a mistake here in previous PR, as the array can still be empty in the else branch
@@ -1046,7 +1047,7 @@ private function turnListIntoConstantArray(FuncCall $countFuncCall, Type $type, | |||
$offsetType = new ConstantIntegerType($i); | |||
$valueTypesBuilder->setOffsetValueType($offsetType, $type->getOffsetValueType($offsetType), true); | |||
} | |||
} else { | |||
} elseif ($type->isConstantArray()->yes()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
compensated the now passed in maybe unbound IntegerRangeType
s
This pull request has been marked as ready for review. |
&& count($unwrappedLeftExpr->getArgs()) >= 1 | ||
&& $unwrappedLeftExpr->name instanceof Name | ||
&& in_array(strtolower((string) $unwrappedLeftExpr->name), ['count', 'sizeof'], true) | ||
&& $rightType->isInteger()->yes() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uses now a proper Type
method instead of && $constantType instanceof ConstantIntegerType
a47ea23
to
5b20101
Compare
Thank you! |
With this PR we also narrow in case of unbound integer ranges
separated from #3373