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

[TypeDeclaration] Handle crash on intersection in Union type on AddMethodCallBasedStrictParamTypeRector #2704

Merged
merged 9 commits into from Jul 27, 2022

Conversation

samsonasik
Copy link
Member

Given the following code:

abstract class SkipIntersectionInUnion
{
    public function prepareParameters(): array
    {
        $parameters =  array_merge($this->getRequestParameters(), [
            'request' => $this->getRequestName(),
        ]);

        $parameters = $this->removeEmptyValues($parameters);

        return array_map(static fn ($parameter) => 'test', $parameters);
    }

    private function removeEmptyValues($input): array
    {
        foreach ($input as &$value) {
            if (! is_array($value)) {
                continue;
            }

            $value = $this->removeEmptyValues($value);
        }

        return array_filter($input, static fn ($val) => true);
    }
}

it produce error:

There was 1 error:

1) Rector\Tests\TypeDeclaration\Rector\ClassMethod\AddMethodCallBasedStrictParamTypeRector\IntersectionTest::test with data set #0 (Symplify\SmartFileSystem\SmartFileInfo Object (...))
Error: Object of class PhpParser\Node\IntersectionType could not be converted to string

Fixes rectorphp/rector#7311

@samsonasik
Copy link
Member Author

Fixed 🎉 /cc @canvural

@canvural
Copy link
Contributor

That was super fast. Thank you!


return array_filter($input, static fn ($val) => true);
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks pretty complex. Is there a way to make this fixture simpler to only contain the intersection type?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated with reduce complexity dc54a42, that's the only code that reproduce the error

@samsonasik
Copy link
Member Author

All checks have passed 🎉 @TomasVotruba it is ready for review.

@samsonasik
Copy link
Member Author

rebased.

@samsonasik
Copy link
Member Author

rebased.

@TomasVotruba
Copy link
Member

👍

@TomasVotruba TomasVotruba merged commit fe0551e into main Jul 27, 2022
@TomasVotruba TomasVotruba deleted the skip-intersection-in-union branch July 27, 2022 07:58
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