Skip to content

Keep numeric-strings in str_repeat()#2914

Merged
ondrejmirtes merged 10 commits into
phpstan:1.11.xfrom
staabm:repeat-numeric-s
May 30, 2024
Merged

Keep numeric-strings in str_repeat()#2914
ondrejmirtes merged 10 commits into
phpstan:1.11.xfrom
staabm:repeat-numeric-s

Conversation

@staabm

@staabm staabm commented Feb 13, 2024

Copy link
Copy Markdown
Contributor

Comment thread tests/PHPStan/Analyser/data/literal-string.php Outdated
@staabm
staabm marked this pull request as ready for review February 13, 2024 09:50
@phpstan-bot

Copy link
Copy Markdown
Collaborator

This pull request has been marked as ready for review.

@ondrejmirtes ondrejmirtes left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please put AccessoryNumericStringType in ConstantStringType::generalize() too.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm afraid this can be a bit tricky. Repeating a numeric type multiple times can lead to a non-numeric type: https://3v4l.org/aRBdZ

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

So we should probably do it only with a constant (literal) types with no decimal points.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

good catch. fixed, thanks.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think it should only be done for strings that only contain digits. Because of these numeric strings: https://3v4l.org/U4bM2

It should also be ensured that the multiplier is not 0.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ohh my, its even different across php versions ;)

https://3v4l.org/m6et3

@staabm
staabm force-pushed the repeat-numeric-s branch 2 times, most recently from 6275102 to 480b972 Compare February 25, 2024 08:02
@staabm
staabm marked this pull request as draft March 18, 2024 15:33
@staabm
staabm force-pushed the repeat-numeric-s branch 3 times, most recently from 3851f2f to 0099b70 Compare April 6, 2024 17:04
@staabm

staabm commented Apr 7, 2024

Copy link
Copy Markdown
Contributor Author

I had a look into blackfire profiles and did not see any bottlenecks/resource hogs

@staabm
staabm marked this pull request as ready for review April 8, 2024 08:28
@phpstan-bot

Copy link
Copy Markdown
Collaborator

This pull request has been marked as ready for review.

Comment thread tests/PHPStan/Analyser/data/literal-string.php Outdated
@staabm
staabm force-pushed the repeat-numeric-s branch from 5449067 to b579b25 Compare April 12, 2024 14:06
@staabm
staabm force-pushed the repeat-numeric-s branch from b579b25 to 5b4a4a2 Compare April 21, 2024 14:32
@ondrejmirtes
ondrejmirtes changed the base branch from 1.10.x to 1.11.x May 30, 2024 13:59
@ondrejmirtes
ondrejmirtes merged commit e099481 into phpstan:1.11.x May 30, 2024
@ondrejmirtes

Copy link
Copy Markdown
Member

Thank you.

@staabm
staabm deleted the repeat-numeric-s branch May 30, 2024 14:35
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.

numeric-string should be implied when a string is simplified

5 participants