Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

ci: add failing test for bug-12585 #3828

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

Open
calebdw wants to merge 1 commit into phpstan:2.1.x
base: 2.1.x
Choose a base branch
Loading
from calebdw:bug-12585

Conversation

@calebdw
Copy link
Contributor

@calebdw calebdw commented Feb 16, 2025

Hello!

This adds failings tests for phpstan/phpstan#12585.

Please note that there's actually two bugs here:

1. Return type

I'm getting errors of the form:

Post::query()->whereHas('user', fn ($q) => $q->where('name', 'test'));
// Anonymous function should return Bug12585\Builder<Bug12585\Model> but returns Bug12585\Builder<Bug12585\User>

despite the parent method having (\Closure(Builder<TRelatedModel>): mixed)|null as the $callback type; and the MethodParameterClosureTypeExtension specifying MixedType as the return type for the replaced closure type.

It seems like the parameter type of the closure phpdoc is being used as the return type...

2. Parameter Type

I am getting errors of the form:

User::query()->whereHas('posts', fn (PostBuilder $q) => $q->where('name', 'test'));
// Parameter #2 $callback of method Bug12585\Builder<Bug12585\User>::whereHas() expects (Closure(Bug12585\Builder<Bug12585\Post>): mixed)|null, 
// Closure(Bug12585\PostBuilder): Bug12585\PostBuilder given.

I think that the MethodParameterClosureTypeExtension is only used to resolve the closure type inside the closure, while the PHPDoc is being used when checking method calls.

Thanks!

owenvoke reacted with thumbs up emoji
Copy link

Please merge!

Copy link
Member

@makroxyz It doesn't make sense to merge failing tests, it needs to be fixed first.

Copy link
Contributor

Looks similar to #3131

calebdw reacted with thumbs up emoji

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /