psalm
psalm copied to clipboard
Internal annotation is propagated to non internal child class
Hello,
https://psalm.dev/r/fb3777b99c
MyClass
uses ExternalCompatibilityClass
but it triggers an InternalMethod
error.
In my example, both methods calls the internal implementation but only example()
triggers the error.
I'm not sure of the expected behaviour but I feel like both methods shouldn't trigger an error.
My example is a minimal reproduction of what's happening with the DoctrineBundle.
The documentations says :
class YourEntityRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, YourEntity::class);
}
}
but ServiceEntityRepository
extends ServiceEntityRepositoryProxy
which is internal.
I found these snippets:
https://psalm.dev/r/fb3777b99c
<?php
namespace B {
/**
* @internal Extend {@see ExternalCompatibilityClass} instead.
*/
class InternalClass
{
public function example(): string
{
return 'example';
}
public function example2(): string
{
return 'example2';
}
}
class ExternalCompatibilityClass extends InternalClass
{
public function example2(): string
{
return parent::example2();
}
}
}
namespace A {
class MyClass extends \B\ExternalCompatibilityClass
{
public function myExample(): void {
$this->example();
$this->example2();
}
}
}
Psalm output (using commit 08afc45):
ERROR: InternalMethod - 33:20 - The method B\InternalClass::example is internal to B but called from A\MyClass::myExample