Skip to content

[DowngradePhp81] Follow parent return type on DowngradeNeverTypeDeclarationRector#1395

Merged
TomasVotruba merged 13 commits intomainfrom
follow-parent-never
Dec 5, 2021
Merged

[DowngradePhp81] Follow parent return type on DowngradeNeverTypeDeclarationRector#1395
TomasVotruba merged 13 commits intomainfrom
follow-parent-never

Conversation

@samsonasik
Copy link
Copy Markdown
Member

Continue of #1390, when the class method implements interface method already has never type, eg:

interface Runnable
{
    public function run(): ?stdClass;
}

class ImplementorRunnable implements Runnable
{
    public function run(): never 
    {
        throw new \Exception('test');
    }
}

above code in php 8.1 is valid ref https://3v4l.org/npms1#v8.1rc3.

But when it downgraded, it currently produce to:

-    public function run(): \stdClass
+    /**
+     * @return never
+     */
+    public function run()

which will make Fatal error:

Fatal error: Declaration of ImplementorRunnable::run() must be compatible with Runnable::run(): ?stdClass

ref https://3v4l.org/aZ2cq#v8.1rc3

This PR try to fix it.

@samsonasik
Copy link
Copy Markdown
Member Author

Fixed 🎉

@samsonasik
Copy link
Copy Markdown
Member Author

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

@TomasVotruba TomasVotruba merged commit 96cf57b into main Dec 5, 2021
@TomasVotruba TomasVotruba deleted the follow-parent-never branch December 5, 2021 13:40
@TomasVotruba
Copy link
Copy Markdown
Member

Thank you

@samsonasik
Copy link
Copy Markdown
Member Author

It seems cause error on rector/rector repo:

Run php bin/rector list --ansi
Rector 96cf57b15bbc4e3b9d5f2f4b58820460c7de448e

Usage:
  command [options] [arguments]

PHP Fatal error:  Declaration of RectorPrefix20211205\Symfony\Component\String\UnicodeString::join($strings, $lastGlue = NULL): RectorPrefix20211205\Symfony\Component\String\UnicodeString must be compatible with RectorPrefix20211205\Symfony\Component\String\AbstractUnicodeString::join($strings, $lastGlue = NULL): RectorPrefix20211205\Symfony\Component\String\AbstractUnicodeString in /home/runner/work/rector/rector/vendor/symfony/string/UnicodeString.php on line 31
Fatal error: Declaration of RectorPrefix20211205\Symfony\Component\String\UnicodeString::join($strings, $lastGlue = NULL): RectorPrefix20211205\Symfony\Component\String\UnicodeString must be compatible with RectorPrefix20211205\Symfony\Component\String\AbstractUnicodeString::join($strings, $lastGlue = NULL): RectorPrefix20211205\Symfony\Component\String\AbstractUnicodeString in /home/runner/work/rector/rector/vendor/symfony/string/UnicodeString.php on line 31

https://github.com/rectorphp/rector/runs/4422515810?check_suite_focus=true#step:5:9

I will check.

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

Successfully merging this pull request may close these issues.

3 participants