You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
@use Trait<T> docblock on anonymous classes ignored #71
class@anonymous …\HasManyTagsTest.php:221$48a::addTag(): Argument $record (template TTag = TextTag)
must be of type TextTag, ShippingMethodTag given
The binding TypePHP reports (TTag = TextTag) is not the @use one; it is inferred from the first addTag() call, so every later call with another union member fails.
Root cause read from the vendor source (v0.10.0 paths): SpecialTypeResolver::parseFileMetadata() (src/Internal/Resolver/SpecialTypeResolver.php:1113-1116) registers $currentClass only for a class, interface, trait or enum token followed by a name token, then files every trait-use docblock it meets under that class (:1121-1124). An anonymous class never becomes a key, so getClassTraitUseDocs('class@anonymous …') stays empty and the anonymous class's @use doc is attributed to the enclosing named class instead. @use on named classes is unaffected.
Expected: the @use docblock on the anonymous class binds TTag = TextTag|ShippingMethodTag, as PHPStan resolves it; both calls are accepted.
Activity
rcalicdan commentedon Sep 17, 2026
@klunejko Hello, I will create a PR and release a quick minor patch for this fix (v0.10.1)