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

Implement ParameterOutTypeExtensions #3083

Open
wants to merge 1 commit into
base: 1.11.x
Choose a base branch
from

Conversation

staabm
Copy link
Contributor

@staabm staabm commented May 19, 2024

@staabm staabm marked this pull request as ready for review May 19, 2024 17:22
@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.

@staabm
Copy link
Contributor Author

staabm commented May 19, 2024

I am not yet sure this feature is useful for the preg_match inference, because the type depends on context: https://github.com/phpstan/phpstan-src/pull/2589/files#diff-65e7da030813493bd5e549d34d89e84b206ed1f44cfc490ffaa52dcba136bd9bR128

@staabm
Copy link
Contributor Author

staabm commented May 20, 2024

Thinking more about it: maybe we need a param out type which depends on the function call return type for the preg_match case

@ondrejmirtes
Copy link
Member

My question is: How important that is? Can it work without this condition in the first release? I have some ideas but it'd require some exploration (conditional types).

Copy link
Member

@ondrejmirtes ondrejmirtes left a comment

Choose a reason for hiding this comment

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

Otherwise 👍

@staabm
Copy link
Contributor Author

staabm commented May 20, 2024

My question is: How important that is? Can it work without this condition in the first release? I have some ideas but it'd require some exploration (conditional types).

we will see when looking into it. I think this PR as is also makes sense in general.

I think conditional param-out types could work.

@staabm staabm force-pushed the param-out-ext branch 3 times, most recently from d7fcc22 to b872fd6 Compare May 24, 2024 15:46
if ($currentParameter === null) {
throw new ShouldNotHappenException();
}

$argValue = $arg->value;
if ($argValue instanceof Variable && is_string($argValue->name)) {
Copy link
Contributor Author

@staabm staabm May 29, 2024

Choose a reason for hiding this comment

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

why does this code path only exec on variables and not e.g. on PropertyFetch?

Copy link
Member

Choose a reason for hiding this comment

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

You can explore that in another PR.

src/Analyser/NodeScopeResolver.php Outdated Show resolved Hide resolved
$argValue = $arg->value;
if ($argValue instanceof Variable && is_string($argValue->name)) {

$paramOutTypes = $this->getParameterOutExtensionsTypes($callLike, $calleeReflection, $currentParameter, $scope);
Copy link
Member

Choose a reason for hiding this comment

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

Will this realistically ever return multiple types? I feel like the union should be done inside this method, and the method should return ?Type.

if ($currentParameter === null) {
throw new ShouldNotHappenException();
}

$argValue = $arg->value;
if ($argValue instanceof Variable && is_string($argValue->name)) {
Copy link
Member

Choose a reason for hiding this comment

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

You can explore that in another PR.

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