Skip to content

Incorrect behavior of AddArrowFunctionReturnTypeRector when dealing with a generic void return #9065

@BackEndTea

Description

@BackEndTea

Bug Report

Subject Details
Rector version last dev-main
Installed as composer dependency

Minimal PHP Code Causing Issue

See https://getrector.com/demo/829dba24-5560-45e3-a696-d4a438753b08

PHPStan playground: https://phpstan.org/r/28d47df0-e978-43b2-bad5-d568bf6b9135

<?php

final class SkipVoidReturn
{
    public function doNohing(string $a): void
    {
        echo $a;
    }

    public function run()
    {
        fn() => $this->executesCallback(fn() => $this->doNohing('a'));
    }

    /**
     * @template T
     * @param callable(): T $callback
     * @return T
     */
    public function executesCallback(callable $callback): mixed
    {
        return $callback();
    }
}

Responsible rules

  • AddArrowFunctionReturnTypeRector

Expected Behavior

Either no change should be made, or a return of null should be added, instead of mixed.
Mixed causes a PHPStan issue, as the return type is incorrect. A return type of null would be (more) correct here.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions