psalm icon indicating copy to clipboard operation
psalm copied to clipboard

False-positive `ReservedWord` issue

Open ghostwriter opened this issue 1 year ago • 4 comments

https://psalm.dev/r/3c8525e655

https://psalm.dev/r/9d2811b8b0

ghostwriter avatar Apr 12 '24 03:04 ghostwriter

I found these snippets:

https://psalm.dev/r/3c8525e655
<?php

declare(strict_types=1);

namespace Tests\Fixture;

final class Test {}
final class Test2 {}

final class IntersectionParameter
{
    public function __invoke(
        Test&Test2 $test
    ): void {
        unset($test);
    }
}
Psalm output (using commit 08afc45):

ERROR: ReservedWord - 13:9 - Parameter cannot be never
https://psalm.dev/r/9d2811b8b0
<?php

declare(strict_types=1);

namespace Tests\Fixture;

final class Test {}

final class Test2 {}

final class IntersectionParameter
{
    public function __invoke(
        Test&Test2 $test
    ): void {
        unset($test);
    }
}

(new IntersectionParameter())(new Test);
Psalm output (using commit 08afc45):

ERROR: InvalidArgument - 20:31 - Argument 1 of Tests\Fixture\IntersectionParameter::__invoke expects never, but Tests\Fixture\Test provided

ERROR: ReservedWord - 14:9 - Parameter cannot be never

psalm-github-bot[bot] avatar Apr 12 '24 03:04 psalm-github-bot[bot]

How can your parameter be both a Test1 and a Test2 when they don't share a parent?

orklah avatar Apr 12 '24 17:04 orklah

Psalm shouldn't report the ResevedWord here though

weirdan avatar Apr 12 '24 17:04 weirdan