Skip to content
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

Open
wants to merge 3 commits into
base: 1.12.x
Choose a base branch
from
Open

Conversation

staabm
Copy link
Contributor

@staabm staabm commented Jan 6, 2025

No description provided.

@staabm
Copy link
Contributor Author

staabm commented Jan 6, 2025

//cc @VincentLanglet since its string accessory business :)

@@ -80,22 +80,23 @@ private function implode(Type $arrayType, Type $separatorType): Type
}

$accessoryTypes = [];
$valueTypeAsString = $arrayType->getIterableValueType()->toString();
Copy link
Contributor Author

@staabm staabm Jan 6, 2025

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

Copy link
Contributor

@VincentLanglet VincentLanglet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome

@staabm staabm force-pushed the impl2 branch 2 times, most recently from b1fb846 to fe52c9e Compare January 6, 2025 17:11
@@ -212,7 +212,7 @@ public function sayHello(int $i): void
// coming from issue #5291
$s = array(1, $i);

assertType('non-falsy-string', implode("a", $s));
assertType('lowercase-string&non-falsy-string', implode("a", $s));
Copy link
Contributor

@mvorisek mvorisek Jan 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assertType('lowercase-string&non-falsy-string', implode("a", $s));
assertType('lowercase-string&non-falsy-string', implode("a", $s));
assertType('uppercase-string&non-falsy-string', implode("A", $s));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants