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 signatures for mb_* functions #717

Merged
merged 6 commits into from Feb 1, 2022

Conversation

staabm
Copy link
Contributor

@staabm staabm commented Oct 15, 2021

inspired by the correspsonding non-mb functions

'mb_strstr' => ['string|false', 'haystack'=>'string', 'needle'=>'string', 'part='=>'bool', 'encoding='=>'string'],
'mb_strtolower' => ['string', 'str'=>'string', 'encoding='=>'string'],
'mb_strtoupper' => ['string', 'str'=>'string', 'encoding='=>'string'],
'mb_strwidth' => ['int', 'str'=>'string', 'encoding='=>'string'],
'mb_strwidth' => ['0|positive-int', 'str'=>'string', 'encoding='=>'string'],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@staabm
Copy link
Contributor Author

staabm commented Oct 15, 2021

.. working on the test errors..

@staabm
Copy link
Contributor Author

staabm commented Jan 11, 2022

rebased

@ondrejmirtes
Copy link
Member

Still doesn't pass.

@staabm staabm marked this pull request as draft February 1, 2022 10:47
@@ -74,6 +75,11 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection,
$returnType = ParametersAcceptorSelector::selectSingle($functionReflection->getVariants())->getReturnType();
$positionEncodingParam = $this->encodingPositionMap[$functionReflection->getName()];

// php8-stubs define a regular int return-type for mb_strlen. use a more precise type instead.
Copy link
Contributor Author

@staabm staabm Feb 1, 2022

Choose a reason for hiding this comment

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

it seems ParametersAcceptorSelector::selectSingle doesn't pick the return type from the functionMap but from the php8 stubs, where mb_strlen is defined with a int return type.

therefore we need this additional if-case

Copy link
Member

Choose a reason for hiding this comment

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

Can you try putting 0|positive-int return type in functionMap_php80delta.php and delete this condition? It might work.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ahh that worked - thanks!

@staabm staabm marked this pull request as ready for review February 1, 2022 13:44
@ondrejmirtes ondrejmirtes merged commit 82e98da into phpstan:master Feb 1, 2022
@ondrejmirtes
Copy link
Member

Thank you!

@staabm staabm deleted the patch-6 branch February 1, 2022 13:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants