Skip to content

NeverType: accept nothing #2110

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

Merged
merged 4 commits into from
Dec 15, 2022
Merged

Conversation

jiripudil
Copy link
Contributor

I was surprised to find out that NeverType accepts everything. Shouldn't it be the opposite? It's the bottom type, it's empty. No value can be of this type. Why accept every value then?

Consider this PR me poking around and waiting to see what builds break.

@ondrejmirtes
Copy link
Member

An idea - only explicit never should have this behaviour. If you have implicit never, it means that the function signature is wrong, and you already have an error at the declaration - no need for a new error when calling it :)

@staabm
Copy link
Contributor

staabm commented Dec 14, 2022

interessting :)

you should have a look at the impact this change has on open issues: https://github.com/phpstan/phpstan-src/actions/runs/3693563281#summary-10085912763 (Issue-Bot summary)

@jiripudil
Copy link
Contributor Author

An idea - only explicit never should have this behaviour. If you have implicit never, it means that the function signature is wrong, and you already have an error at the declaration - no need for a new error when calling it :)

Oh, thanks a lot for this comment! This probably explains why it has been implemented to accept everything. I'll update this so that only the behaviour of explicit never is changed 👍

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.

Thank you, it makes total sense and issue bot agrees :)

Please:

  1. Add a regression test for the one implemented feature request that asks for this :)
  2. Please add a test that shows that explicit never can be passed into explicit never :)

@ondrejmirtes ondrejmirtes merged commit 25c8312 into phpstan:1.9.x Dec 15, 2022
@ondrejmirtes
Copy link
Member

Thank you!

@ondrejmirtes
Copy link
Member

I'm really gonna go crazy here :D Because of this change, this now reports problem like this:


 ------ ----------------------------------------------------------------------- 
  Line   test.php                                                
 ------ ----------------------------------------------------------------------- 
  73     Parameter #1 $element of method                                        
         Doctrine\Common\Collections\ArrayCollection<*NEVER*,*NEVER*>::add()    
         expects *NEVER*,                                                       
         object given.                                                    
 ------ ----------------------------------------------------------------------- 

So if you create a new ArrayCollection and immediately try to add something to it, it's gonna report an error.

Maybe we'll have to postpone this until generics are smarter 🤔

@herndlm
Copy link
Contributor

herndlm commented Dec 16, 2022

That's phpstan/phpstan#8511 / phpstan/phpstan#6731 again, right? Did you not see the failing test Ondřej? :P

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants