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

ArrayFilterFunctionReturnTypeReturnTypeExtension handle error types #2794

Merged
merged 2 commits into from
Nov 28, 2023

Conversation

mglaman
Copy link
Contributor

@mglaman mglaman commented Nov 28, 2023

@phpstan-bot
Copy link
Collaborator

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

@@ -54,9 +55,13 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection,
}

$arrayArgType = $scope->getType($arrayArg);
$arrayArgType->isArray();
Copy link
Member

Choose a reason for hiding this comment

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

This is a no-op.

Copy link
Member

Choose a reason for hiding this comment

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

The right solution is:

$arrays = TypeUtils::toBenevolentUnion($arrayArgType)->getArrays();
$arrayArgType = TypeCombinator::union(...$arrays);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, whoops that was a debugging line I thought I had deleted. Thanks for the direction, I will try it out.

Copy link
Member

Choose a reason for hiding this comment

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

Or maybe just would work too:

$arrayArgType = TypeUtils::toBenevolentUnion($arrayArgType);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That worked!

Copy link
Member

Choose a reason for hiding this comment

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

And please listen to the bot 😊 #2794 (comment)

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'll rebase off of 1.10.x and change the PR, I was waiting for "this is a horrible wrong approach" or not. Rebasing now

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, rebased off of 1.10.x and changed the PR base

@mglaman mglaman changed the base branch from 1.11.x to 1.10.x November 28, 2023 22:15
@mglaman mglaman changed the base branch from 1.10.x to 1.11.x November 28, 2023 22:23
@mglaman mglaman force-pushed the array-filter-on-invalid-union branch from 0e0a367 to cf5484c Compare November 28, 2023 22:26
@mglaman mglaman changed the base branch from 1.11.x to 1.10.x November 28, 2023 22:27
@ondrejmirtes ondrejmirtes merged commit 093bbb2 into phpstan:1.10.x Nov 28, 2023
153 checks passed
@ondrejmirtes
Copy link
Member

Thank you!

@mglaman
Copy link
Contributor Author

mglaman commented Nov 28, 2023

Thanks for the guidance along the way!

@mglaman mglaman deleted the array-filter-on-invalid-union branch November 28, 2023 22:30
@mvorisek
Copy link
Contributor

mvorisek commented Dec 2, 2023

Fixed also phpstan/phpstan#8638, 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
4 participants