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

Fix substr() type narrowing for maybe one-length result #3081

Merged
merged 2 commits into from
May 30, 2024

Conversation

staabm
Copy link
Contributor

@staabm staabm commented May 17, 2024

@staabm staabm marked this pull request as ready for review May 17, 2024 08:56
@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.

@@ -54,7 +54,7 @@ public function doMbSubstr(string $s, $nonEmpty, $positiveInt, $postiveRange, $n
assertType('string', mb_substr($s, 0, $positiveInt));
assertType('non-empty-string', mb_substr($nonEmpty, 0, $positiveInt));

assertType('non-falsy-string', mb_substr("déjà_vu", 0, $positiveInt));
assertType('non-empty-string', mb_substr("déjà_vu", 0, $positiveInt));
Copy link
Contributor

Choose a reason for hiding this comment

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

We could keep non-falsy-string here since there is no 0 in the string constant @staabm

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I also though about that. I think such a case is pretty unlikely and supporting it would mean a lot of complication of the extension.

therefore I decided against supporting that

@staabm staabm force-pushed the substr-maybeone branch 2 times, most recently from d27644a to ed6fd44 Compare May 24, 2024 18:33
@ondrejmirtes ondrejmirtes merged commit ac7b886 into phpstan:1.11.x May 30, 2024
74 checks passed
@ondrejmirtes
Copy link
Member

Thank you.

@staabm staabm deleted the substr-maybeone branch May 30, 2024 14:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants