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: Support resolving of constants in patterns #3265

Merged
merged 3 commits into from
Jul 25, 2024

Conversation

staabm
Copy link
Contributor

@staabm staabm commented Jul 25, 2024

Refactors RegexArrayShapeMatcher to re-use InitializerExprTypeResolver

closes phpstan/phpstan#11384

staabm added 2 commits July 25, 2024 15:19
Refactors RegexArrayShapeMatcher to re-use InitializerExprTypeResolver
@staabm staabm changed the base branch from 1.12.x to 1.11.x July 25, 2024 13:21
@phpstan-bot
Copy link
Collaborator

You've opened the pull request against the latest branch 1.12.x. If your code is relevant on 1.11.x and you want it to be released sooner, please rebase your pull request and change its target to 1.11.x.

@staabm
Copy link
Contributor Author

staabm commented Jul 25, 2024

I think I now have a better understand how the InitializerExprTypeResolver works and I will have a look whether we can do a similar thing within RegularExpressionQuotingRule

@staabm staabm marked this pull request as ready for review July 25, 2024 13:27
@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.

@Seldaek
Copy link
Contributor

Seldaek commented Jul 25, 2024

Cool, less code and less bugs :D

} else {
$right = $scope->getType($concat->right);
}
$resolveConcat = static function (Expr $expr) use (&$resolveConcat, $scope) {
Copy link
Member

Choose a reason for hiding this comment

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

These are usually memory leaks. It'd be nicer to have this as a private method.

Copy link
Contributor Author

@staabm staabm Jul 25, 2024

Choose a reason for hiding this comment

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

I went with a inline class, hopefully that works for you.
didn't have a better idea on how to get the lexical $scope variable into the callable

return TypeCombinator::union(...$strings);
};

return $this->initializerExprTypeResolver->getConcatType($concat->left, $concat->right, static fn (Expr $expr): Type => $resolver->resolve($expr));
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure if this is supported by the php8.1=>7.2 transpile but hopefully :)

Suggested change
return $this->initializerExprTypeResolver->getConcatType($concat->left, $concat->right, static fn (Expr $expr): Type => $resolver->resolve($expr));
return $this->initializerExprTypeResolver->getConcatType($concat->left, $concat->right, $resolver->resolve(...));

Copy link
Member

Choose a reason for hiding this comment

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

It's not :)

@ondrejmirtes ondrejmirtes merged commit 2f10677 into phpstan:1.11.x Jul 25, 2024
447 of 455 checks passed
@ondrejmirtes
Copy link
Member

Thank you.

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.

Support for constants in regex concatenations
4 participants