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

Resolve object type by class const fetch in switch statement #745

Closed
wants to merge 2 commits into from

Conversation

marmichalski
Copy link
Contributor

@marmichalski marmichalski commented Oct 27, 2021

Relates to: phpstan/phpstan#5843

I'm not really sure how good (or bad) this solution is. Just glued it together and it seems to work.

Any tips on how I can include a test case for this and also improve this solution are more than welcome.

@staabm
Copy link
Contributor

staabm commented Oct 27, 2021

you should add a unit test which shows it fixes the initally reported problem

@staabm
Copy link
Contributor

staabm commented Oct 28, 2021

If you need assistance feel free to ask

@marmichalski
Copy link
Contributor Author

If you need assistance feel free to ask

That's what I did in my opening comment 😛

Anyway, I've pushed the tests - don't know if there is a need for both of them, as they handle quite similar case.

Also, there is a room for improvement in case of bug-4896, as the object is a known union type, the Throwable case could be reported as something that will never happen, I guess. But that's something for separate issue.

Thank you, @staabm.

@staabm
Copy link
Contributor

staabm commented Oct 28, 2021

That's what I did in my opening comment

sorry I didn't read properly.

Anyway, I've pushed the tests - don't know if there is a need for both of them, as they handle quite similar case.

the PR looks good to me - lets see what ondrej thinks about it.
did you make sure that the tests fail without the fix applied?

Also, there is a room for improvement in case of bug-4896, as the object is a known union type, the Throwable case could be reported as something that will never happen, I guess. But that's something for separate issue.

agree that this is a separate issue. would be great to have an open issue for that, in case its not yet filled.

great job.

@marmichalski
Copy link
Contributor Author

Anyway, I've pushed the tests - don't know if there is a need for both of them, as they handle quite similar case.

the PR looks good to me - lets see what ondrej thinks about it. did you make sure that the tests fail without the fix applied?

  • bug-4896:
    • Call to an undefined method DateInterval|DateTime::getTimestamp().
  • bug-5843:
    • Call to an undefined method object::modify().
    • Call to an undefined method object::getPrevious().

Also, there is a room for improvement in case of bug-4896, as the object is a known union type, the Throwable case could be reported as something that will never happen, I guess. But that's something for separate issue.

agree that this is a separate issue. would be great to have an open issue for that, in case its not yet filled.

I will remove this from bug-4896 test, as this is not related and open a new issue.

great job.

👍

@ondrejmirtes
Copy link
Member

Thank you! Merged as: 9167061

And improved with: c1579f1 (by also making it work with === and thus with match).

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