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

implemented ConstantStringType inference for str_repeat #1030

Merged
merged 3 commits into from Feb 22, 2022

Conversation

staabm
Copy link
Contributor

@staabm staabm commented Feb 22, 2022

@clxmstaab clxmstaab force-pushed the str-repeat branch 2 times, most recently from ed665c1 to 14b954c Compare February 22, 2022 09:13
@@ -42,6 +42,10 @@ public function getTypeFromFunctionCall(
return new ConstantStringType('');
}

if ($inputType instanceof ConstantStringType && $multiplierType instanceof ConstantIntegerType) {
return new ConstantStringType(str_repeat($inputType->getValue(), $multiplierType->getValue()));
Copy link
Member

Choose a reason for hiding this comment

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

The code will crash when analysing code like this: https://3v4l.org/XRaOj

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good point. added a test and made it return NeverType on negative multiplier

@ondrejmirtes
Copy link
Member

Thank you.

@staabm staabm deleted the str-repeat branch February 22, 2022 16:27
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