psalm icon indicating copy to clipboard operation
psalm copied to clipboard

False positive PossiblyUnusedReturnValue when value is used via interface but not in concrete class

Open Miters-Community opened this issue 1 year ago • 2 comments

Reproduce: https://psalm.dev/r/ba6aad7b6a

TestImpl::method1 is called within the TestImpl class, and the return value is not used.

But at the mean time, this method is belongs to an interface, so it should not report this error.

Originally posted by @yyueniao in https://github.com/vimeo/psalm/issues/6021#issuecomment-1766452210

Miters-Community avatar Oct 18 '23 10:10 Miters-Community

I found these snippets:

https://psalm.dev/r/ba6aad7b6a
<?php

interface TestInterface {
	public function method1():string;
    public function method2():void;
}

class TestImpl implements TestInterface {
    public function method2():void{
    	$this->method1();
    }
    public function method1():string{
    	return "test";
    }
}

function main(TestInterface $test):void {
	echo $test->method1();
    $test->method2();
}

main(new TestImpl());
Psalm output (using commit 24168f6):

ERROR: PossiblyUnusedReturnValue - 12:31 - The return value for this method is never used

psalm-github-bot[bot] avatar Oct 18 '23 10:10 psalm-github-bot[bot]

@orklah Sorry i misused a wrong account, but it is me

yyueniao avatar Oct 18 '23 10:10 yyueniao