phpstan-src icon indicating copy to clipboard operation
phpstan-src copied to clipboard

Fix bug #9630 (?)

Open FoxCie opened this issue 5 months ago • 3 comments

Hello, I am trying to make use of generics work when using traits from traits (see https://github.com/phpstan/phpstan/issues/9630). It works totally fine when using a single file, but not when separating classes and traits in different files.

The main reason, from what I have seen, is that caching is made using file names, and when using traits, the file name used as the cache key is the one of the class that is using the traits, which is not the filename of the direct user of the trait if some traits are used in traits.

For example, if a class C uses trait T1 that uses trait T2, the cache key when computing T2 in the context of C would be computed with the file in which T1 is defined, when it is expected to be the one in which C is defined.

That is my comprehension of what is done there, but I may be completely mistaken. I tried to handle the case of the wrong cache key by searching in the cache with the filename of the class using the traits if the search fails with original parameters. I am not sure my PR fixes everything correctly, because I was unable to build the PHAR package locally to test it on my real project in which the bug happens. It seemed to work on an example I made, but I may have failed reproducing the behaviour correctly.

This PR is work in progress, I tried to see if I could download the PHAR package from the artifacts of the CI to test.

FoxCie avatar Aug 26 '24 14:08 FoxCie