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

RegexArrayShapeMatcher - when all groups are optional return a more… #3189

Merged
merged 21 commits into from
Jun 30, 2024

Conversation

staabm
Copy link
Contributor

@staabm staabm commented Jun 25, 2024

@staabm staabm marked this pull request as ready for review June 25, 2024 16:08
@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.

@staabm
Copy link
Contributor Author

staabm commented Jun 25, 2024

quest for another PR: how to get smarter for alternations in the regex.
atm our typing gets wonkey when the regex patter contains | with capturing groups in the alternation.

maybe tomorrow ;)

@staabm staabm marked this pull request as draft June 26, 2024 05:53
@staabm
Copy link
Contributor Author

staabm commented Jun 30, 2024

took me a lot of attempts but I think the current design works now.

when a regex contains only a single optional capturing group, we build a more precise constant type.
there is still room for improvement but I think its a good next step.

@staabm staabm marked this pull request as ready for review June 30, 2024 10:57
@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.


namespace PHPStan\Type\Php;

class RegexNonCapturingGroup
Copy link
Contributor Author

@staabm staabm Jun 30, 2024

Choose a reason for hiding this comment

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

the optional groups detection, now also takes non-capturing groups into account... these do not capture results itself, but might impact nested capturing groups

Comment on lines +96 to +97
// if only one top level capturing optional group exists
// we build a more precise constant union of a empty-match and a match with the group
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 am limiting to this specific case for now, because whether $matches contains a offset or not depends on many factors. I did this already for more stuff, but it was easily breaking stuff.

will bring back more sophiscated stuff in future PRs

@ondrejmirtes ondrejmirtes merged commit 271766e into phpstan:1.11.x Jun 30, 2024
452 of 455 checks passed
@ondrejmirtes
Copy link
Member

Thank you!

@staabm staabm deleted the non-offset branch June 30, 2024 11:18
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