-
Notifications
You must be signed in to change notification settings - Fork 493
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
More precise implode() return type #3774
base: 1.12.x
Are you sure you want to change the base?
Conversation
//cc @VincentLanglet since its string accessory business :) |
@@ -80,22 +80,23 @@ private function implode(Type $arrayType, Type $separatorType): Type | |||
} | |||
|
|||
$accessoryTypes = []; | |||
$valueTypeAsString = $arrayType->getIterableValueType()->toString(); |
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.
the actual change is here: we use toString
as the implode
function internally casts everything.
that way the string types detection also works for unions of strings and non-strings (e.g. 2|'a'
) and so we get more precise results
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.
Awesome
b1fb846
to
fe52c9e
Compare
75c4610
to
224d41d
Compare
fd8d5f3
to
8e351b9
Compare
@@ -49,6 +61,6 @@ public function constArrays5($constArr) { | |||
|
|||
/** @param array{0: 1, 1: 'a'|'b', 3?: 'c'|'d', 4?: 'e'|'f', 5?: 'g'|'h', 6?: 'x'|'y'} $constArr */ | |||
public function constArrays6($constArr) { | |||
assertType("string", implode('', $constArr)); | |||
assertType("literal-string&lowercase-string&non-falsy-string", implode('', $constArr)); |
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.
Memo to me: Literal string is wrong here
No description provided.