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

Generic of true value is typed to bool not true #7283

Closed
MartkCz opened this issue May 21, 2022 · 3 comments
Closed

Generic of true value is typed to bool not true #7283

MartkCz opened this issue May 21, 2022 · 3 comments

Comments

@MartkCz
Copy link

MartkCz commented May 21, 2022

Code snippet that reproduces the problem

https://phpstan.org/r/a3fd6456-8fa5-4913-a17f-9132cd2e1221

Expected output

onlyTrue return true[] instead of bool[]

@ondrejmirtes ondrejmirtes added this to the Generics milestone May 21, 2022
@rvanvelzen
Copy link
Contributor

This is the same problem as #6653 - the type is generalized because the bound is implied mixed.

@ondrejmirtes
Copy link
Member

Last night I came up with the idea that we mostly shouldn't generalize the generic type variables, except when they're in object generics, like Foo<int>.

Here's the resulting PR: phpstan/phpstan-src#2818

We can't do this for objects, because I want new Collection([1, 2, 3]) to become Collection<int>. This could be improved in the future thanks to this suggestion: #6732 (comment) (but it's pretty complex to implement so for now it has to wait).

The new behaviour now only applies to bleeding edge (https://phpstan.org/blog/what-is-bleeding-edge) so definitely enable it to get the taste of the future 👍

Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants