psalm icon indicating copy to clipboard operation
psalm copied to clipboard

Internal annotation is propagated to non internal child class

Open Braxilior opened this issue 10 months ago • 1 comments

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.

Braxilior avatar Apr 18 '24 08:04 Braxilior

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

psalm-github-bot[bot] avatar Apr 18 '24 08:04 psalm-github-bot[bot]