Skip to content

Incorrect UnusedReturnValue for a recursive private method #11545

@dabrowiecki

Description

@dabrowiecki

If you have a private method used recursively and return type is used only in recursion, psalm incorrectly emits UnusedReturnValue.

Example code:

class A {
    private array $cache = [];
    public function a(): void {
        $this->buildCacheRecursively(6);
    }
    
    private function buildCacheRecursively(int $id): int
    {
        if ($id === 1) {
            return 1;
        }
        
        $this->cache[$id] = $id * $this->buildCacheRecursively($id-1);
        return $this->cache[$id];
    }
}

https://psalm.dev/r/029a1d1479

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions