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
Improve return types for array_fill_keys
and array_combine
#1139
Improve return types for array_fill_keys
and array_combine
#1139
Conversation
7542a89
to
572960f
Compare
572960f
to
af04640
Compare
f65641a
to
419d8ef
Compare
@@ -65,8 +68,24 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection, | |||
} | |||
} | |||
|
|||
if ($keysParamType instanceof ArrayType) { |
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.
With instanceof ArrayType
condition, you're excluding:
non-empty-array
(that's IntersectionType)- Unions of array shapes
Better solution is $keysParamType->isArray()->yes()
. Instead of ->getItemType()
, you should use ->getIterableValueType()
.
Feel free to fix other instances in this extension too - I see $valuesParamType instanceof ArrayType
as well.
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.
Updated and added tests.
419d8ef
to
87f4058
Compare
87f4058
to
ecd0dcb
Compare
Thank you! |
This PR improves return types for
array_fill_keys
andarray_combine
functions. This two functions are kinda special, because they try to cast the key types to string. Sotrue
becomes1
, an object that has__toString
becomesstring
etc. This PR adds that.