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

Union type int|false is converted to type int|bool when using template. #7984

Closed
vdauchy opened this issue Sep 10, 2022 · 5 comments
Closed
Labels
Milestone

Comments

@vdauchy
Copy link

vdauchy commented Sep 10, 2022

Bug report

Union type int|false is converted to type int|bool when using template.

Code snippet that reproduces the problem

https://phpstan.org/r/fd175ccc-e72b-4b2c-9adf-008f02e66533

Expected output

No error shall be detected.

Did PHPStan help you today? Did it make you happy in any way?

Hi, thanks for your work, I'm having a relaxing time solving issues in my libs <3

@staabm
Copy link
Contributor

staabm commented Sep 11, 2022

the problem happens because of the templated closure involved.

without a template type it works as expected:
https://phpstan.org/r/b0babc02-b847-4c0c-819c-420f16f6582f

@rvanvelzen I think you are the expert in this area

@rvanvelzen
Copy link
Contributor

This is due to template type generalisation. See phpstan/phpstan-src#1206 for more info.

@ondrejmirtes ondrejmirtes added this to the Generics milestone Sep 20, 2022
@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 👍

@vdauchy
Copy link
Author

vdauchy commented Dec 11, 2023

I received the notification for your PR, thanks for all of this 🥳

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.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants