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

Generic return type is used as native [ReturnTypeDeclarationRector] #7213

Closed
FrancoisPog opened this issue Jun 7, 2022 · 3 comments
Closed
Labels

Comments

@FrancoisPog
Copy link

FrancoisPog commented Jun 7, 2022

Bug Report

Subject Details
Rector version v0.13.4
Installed as Composer dependency  

The generic return type from phpdoc is used for the native return type, \T which does not exist.

Minimal PHP Code Causing Issue

Demo: https://getrector.org/demo/5a20665a-b61f-4923-8b9a-aa9cb5c3a8ea

Responsible rules

  • ReturnTypeDeclarationRector

Failing test

rectorphp/rector-src@main...FrancoisPog:patch-1
rectorphp/rector-src#2454

<?php

class AbstractController 
{
    private readonly UseCaseBusInterface $useCaseBus;

    /**
     * @template T
     *
     * @param UseCaseInterface<T> $useCase
     *
     * @return T
     */
-  protected function execute(UseCaseInterface $useCase): mixed
+  protected function execute(UseCaseInterface $useCase): \T
    {
        return $this->useCaseBus->execute($useCase);
    }
}

N.B.

This similar example works correctly : https://getrector.org/demo/1faeadb8-431b-43d4-83e6-b74c1cd408bd;

<?php

interface UseCaseBusInterface
{
    /**
     * @template T
     *
     * @param UseCaseInterface<T> $useCase
     *
     * @return T
     */
    public function execute(UseCaseInterface $useCase): mixed; // no change
}

Expected Behaviour

The return type should not be changed IMHO 🤔

Thanks

By the way, thanks for this awesome tool, what a fantastic job ! 💯

@FrancoisPog FrancoisPog added the bug label Jun 7, 2022
@FrancoisPog FrancoisPog changed the title Generic return type is used as native Generic return type is used as native [ReturnTypeDeclarationRector] Jun 7, 2022
@samsonasik
Copy link
Member

samsonasik commented Jun 8, 2022

Could you create failing test case PR for it? You can click "Create a Test" button at the demo page

@FrancoisPog
Copy link
Author

Could you create failing test case PR for it? You can click "Create a Test" button at the demo page

It's done, tell me if I did something wrong or if there is something more I can do.

rectorphp/rector-src@main...FrancoisPog:patch-1

@samsonasik
Copy link
Member

You can click "Create pull request" button for it, better to rename fixture class with something like SkipGeneric with file name renamed to skip_generic.php.inc

samsonasik added a commit to rectorphp/rector-src that referenced this issue Jun 9, 2022
samsonasik added a commit to rectorphp/rector-src that referenced this issue Jun 10, 2022
samsonasik added a commit to rectorphp/rector-src that referenced this issue Jun 10, 2022
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

2 participants