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

Allow typing things as scalar&!empty? #2449

Closed
Ocramius opened this issue Dec 9, 2019 · 2 comments
Closed

Allow typing things as scalar&!empty? #2449

Ocramius opened this issue Dec 9, 2019 · 2 comments

Comments

@Ocramius
Copy link
Contributor

Ocramius commented Dec 9, 2019

While trying to refine type annotations for webmozart/assert, I noticed that it is not currently possible to use intersection types together with the empty construct.

My attempt was to add @psalm-assert string&!empty (as an example), as well as other combinations of empty and !empty, but the empty and !empty types seem to only be parsed when in a standalone context, and not in union/intersection types.

muglug added a commit that referenced this issue Dec 9, 2019
@muglug
Copy link
Collaborator

muglug commented Dec 9, 2019

Intersections of assertions should just be represented as separate @psalm-assert annotations:

/**
 * @param mixed $value
 * @psalm-assert scalar $value
 * @psalm-assert !empty $value
 */
function assertScalarNotEmpty($value) : void {}

That doesn't quite work in the current Psalm release, but I've just fixed things so it should:

https://psalm.dev/r/4892c18ffb

@Ocramius
Copy link
Contributor Author

Ocramius commented Dec 9, 2019

That doesn't *quite8 work in the current Psalm release, but I've just fixed things so it should:

I missed this detail: will do another iteration on webmozart/assert after these are through in a release 👍

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

No branches or pull requests

2 participants