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

Support for Disjunctive Normal Form Types #558

Open
stof opened this issue Aug 22, 2022 · 4 comments
Open

Support for Disjunctive Normal Form Types #558

stof opened this issue Aug 22, 2022 · 4 comments
Labels

Comments

@stof
Copy link
Member

stof commented Aug 22, 2022

See https://wiki.php.net/rfc/dnf_types

We need to make sure they can be doubled properly, with tests ensuring they work fine.

@stof stof added the PHP8.2 label Aug 22, 2022
@kschatzle
Copy link
Contributor

kschatzle commented Sep 9, 2022

Noting that getTypes() for the following code may now (PHP8.2) return 'ReflectionIntersectionType':

elseif ($reflectionType instanceof ReflectionUnionType) {
$types = $reflectionType->getTypes();
}

elseif ($type instanceof ReflectionUnionType) {
$types = $type->getTypes();
}

I'm unsure what the underlying decision to not support ReflectionIntersectionType was. My assumption is that it was difficult (maybe impossible) to create the double with the necessary values.

Possible solution would be to loop through types looking for ReflectionIntersectionType and throwing a nice Exception.

It does throw an err. The class effectively turns this:

    public function doSomething () : A|(B&D)|null
    {

    }

Into

        public  function doSomething(): A|B&D|null { //At least one err here. Should be A|(B&D)|null I believe.
            return $this->getProphecy()->makeProphecyMethodCall(__FUNCTION__, func_get_args());
        }

All this said, I'm confused by something, so going to ping the php-src group. Either found a bug or something I don't understand.

@ciaranmcnulty
Copy link
Member

I'm unsure what the underlying decision to not support ReflectionIntersectionType was

Simply that PHP 8.1 was coming and we wanted a clear exception to be thrown here rather than a hard error

Nobody's made it work since (or TBH has raised an issue)

@ciaranmcnulty
Copy link
Member

if someone wants to make intersection types work that's fine, to be clear

@stof
Copy link
Member Author

stof commented Sep 9, 2022

The issue tracking proper support for intersection types is #535, but nobody worked on it yet.

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

No branches or pull requests

3 participants