Skip to content

Conversation

@calebdw
Copy link
Contributor

@calebdw calebdw commented Jan 23, 2026

Hello!

Git bisect shows that commit d8ec11f introduced a regression in nested trait @use resolution, e.g., the following no longer passes the template to the base trait:

/** @template TBuilder of Builder<*> */
trait HasBuilder
{
    /** @use BaseHasBuilder<TBuilder> */
	use BaseHasBuilder;
    // other methods
}

This bug only seems to show up when the classes are in different files and namespaces, so it was impossible to replicate on the playground (see https://phpstan.org/r/985be0cb-f0ba-47e9-8f3c-3f7f63dccdfa). In the e2e test, I also tried to just have a data/ directory with framework.php and a src.php files that had the respective namespace and classes in them but that passed and did not replicate the failure. So sorry for the 6 individual classes / files but this was the only way that I could replicate.

Note

I'm not sure if this is the best fix, this was just suggested by the AI agent that was helping me diagnose the cause of this regression. This does however, fix the issue I was having...

Warning

There seems to be some additional caching going on that's not being cleared by phpstan clear-result-cache. Running the following command before and after the commit that fixes the issue does not result in a different output unless the tmp/ directory is completely cleared in between runs (i.e., if ran before the fix and then ran after the fix the command still results in an error when it should be passing; and the same backwards, running after the fix and then before the fix results in a passing command which should be failing):

  # this does not completely clear all state between runs
  cd e2e/nested-trait-use && ../../bin/phpstan clear-result-cache && ../../bin/phpstan analyze
  # instead need to manually clear the entire cache between runs with
  cd e2e/nested-trait-use && rm -rf ./tmp/cache && ../../bin/phpstan analyze

Thanks!

@calebdw calebdw force-pushed the calebdw/push-zttzmqwtlpur branch from 9c90049 to 9f8e0a9 Compare January 23, 2026 21:14
@ondrejmirtes
Copy link
Member

There seems to be some additional caching going on that's not being cleared by phpstan clear-result-cache. Running the following command before and after the commit

That's what variable cache key (2nd parameter of the load() method is for. When the cache becomes stale, you need to bump the number in the source code.

@calebdw calebdw force-pushed the calebdw/push-zttzmqwtlpur branch from 9f8e0a9 to 93ea1f2 Compare January 23, 2026 21:55
@calebdw
Copy link
Contributor Author

calebdw commented Jan 23, 2026

I suppose it needs to be bumped then as part of this fix to clear out all the bad caches?

@ondrejmirtes ondrejmirtes merged commit e50d059 into phpstan:2.1.x Jan 23, 2026
347 of 351 checks passed
@ondrejmirtes
Copy link
Member

Thank you!

@calebdw calebdw deleted the calebdw/push-zttzmqwtlpur branch January 23, 2026 22:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants