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

feat: Handle native intersection types #7454

Merged
merged 6 commits into from Jan 22, 2022

Conversation

petewalker
Copy link
Contributor

@petewalker petewalker commented Jan 21, 2022

I've raised this against 4.x, but not sure if it's for 4.x or master?

Adds native intersection type handling to psalm, removing the previous UnexpectedValueException.

Where an intersection is found in the parse tree, the types are resolved using the existing Type::intersectUnionTypes function, which I assume is being used when they're encountered in the existing docblock annotations.

I've added a handful of tests to cover this, but they're certainly not exhaustive. Are there any specific edge cases I should target?

This change feels way too simple... so apologies if I've missed something fundamental..!

Resolves #6413

Adds native intersection type handling to psalm, removing the previous `UnexpectedValueException`.

Where an intersection is found in the parse tree, the types are resolved using the existing `Type::intersectUnionTypes` function, which I assume is being used when they're encountered in the existing docblock annotations.

I've added a handful of tests to cover this, but they're certainly not exhaustive. Are there any specific edge cases I should target?

This change feels way too simple... so apologies if I've missed something fundamental..!
@petewalker petewalker marked this pull request as ready for review January 21, 2022 13:31
@AndrolGenhald
Copy link
Collaborator

AndrolGenhald commented Jan 21, 2022

I would add a test to make sure A&(B|C) is never allowed in PHP type signatures, it probably already works correctly but we definitely want to catch that and make sure it doesn't break in the future. Also add a test to make sure A&B is caught for PHP < 8.1 (looks like that one might need tweaking to make it work).

@petewalker
Copy link
Contributor Author

I would add a test to make sure A&(B|C) is never allowed in PHP type signatures, it probably already works correctly but we definitely want to catch that and make sure it doesn't break in the future.

👍 This triggers a ParseError currently anyway

Also add a test to make sure A&B is caught for PHP < 8.1 (looks like that one might need tweaking to make it work).

I can try to do this, but there doesn't seem to be a similar rule for A|B in PHP < 8.0? What should do psalm throw in these cases?

@orklah
Copy link
Collaborator

orklah commented Jan 21, 2022

Please target on master, We try to target new features on master to avoid future maintenance on old branches.

@petewalker petewalker changed the base branch from 4.x to master January 21, 2022 17:33
@petewalker
Copy link
Contributor Author

I've retargeted to master and added some extra checks for unions in PHP < 8.0 and intersections in PHP < 8.1.

It's meant allowing TypeHintResolver to raise issues to the IssueBuffer. I'm not sure if that's desirable or not..!

@AndrolGenhald
Copy link
Collaborator

AndrolGenhald commented Jan 21, 2022

I can try to do this, but there doesn't seem to be a similar rule for A|B in PHP < 8.0? What should do psalm throw in these cases?

Well that's not great.

...added some extra checks for unions in PHP < 8.0 and intersections in PHP < 8.1

That'll be good to have! Looks like it needs to exclude stubs and ignored files somehow though.

@petewalker
Copy link
Contributor Author

Woops... well, that broke a lot of stuff - more to do..!

@AndrolGenhald
Copy link
Collaborator

AndrolGenhald commented Jan 21, 2022

@petewalker Try IssueBuffer::maybeAdd, that might solve it. I'm not really sure that IssueBuffer::add should be used hardly anywhere, we might want to look over current uses of it at some point and make sure they're not supposed to be suppressible.

@petewalker
Copy link
Contributor Author

@orklah @AndrolGenhald - I think it's all good to go now

@petewalker
Copy link
Contributor Author

I'm not sure that failing test has anything to do with my change? Unless I'm missing something.

@orklah orklah added the release:feature The PR will be included in 'Features' section of the release notes label Jan 22, 2022
@orklah
Copy link
Collaborator

orklah commented Jan 22, 2022

Thanks! That looks great!

This was referenced Dec 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: Need review release:feature The PR will be included in 'Features' section of the release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants