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

implement gettype() inference in TypeSpecifier #1611

Merged
merged 3 commits into from Aug 12, 2022

Conversation

staabm
Copy link
Contributor

@staabm staabm commented Aug 12, 2022

@staabm staabm marked this pull request as ready for review August 12, 2022 07:26
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.

Please test some more scenarios.

  1. Three equal signs: if (gettype($x) === 'int')
  2. Negative context:
// $x is int|string|bool
if (gettype($x) === 'integer') {
    // assert int
    return;
}

// assert string|bool
  1. BooleanOr:
if (gettype($x) === 'string' || gettype($x) === 'integer') {
    // assert int|string
}

@staabm
Copy link
Contributor Author

staabm commented Aug 12, 2022

great feedback thx. added tests and simplified the implementation based on it :)

@ondrejmirtes ondrejmirtes merged commit eb40029 into phpstan:1.8.x Aug 12, 2022
@ondrejmirtes
Copy link
Member

Thank you!

@staabm staabm deleted the gettype-specifying branch August 12, 2022 13:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants