Validate @phpstan-sealed types are subtypes of the annotated type - #6425
Validate @phpstan-sealed types are subtypes of the annotated type#6425klimick wants to merge 5 commits into
Conversation
|
You're right, my original constraint was too strict. I agree that a non-final class can represent an open branch of the hierarchy, even if it is not itself a subtype of the annotated type. I relaxed the validation accordingly: PHPStan now reports an error only when a listed final class or enum is not a subtype of the annotated type. I also added regression tests covering both the valid non-final branch and the invalid final-class case. I also agree that this should be introduced in bleeding edge, and added the check there. |
| $sealedTypeReflection = $this->reflectionProvider->getClass($class); | ||
|
|
||
| if ( | ||
| BleedingEdgeToggle::isBleedingEdge() |
There was a problem hiding this comment.
If you look at conf/bleedingEdge.neon, you can see that we use dedicated featureToggle for this "new feature".
Juste add one toggle in conf/config.neon, with a default value of false, then enable in bleedingEdge.neon.
Inject the param here and use it.
There was a problem hiding this comment.
So that's how bleeding edge works...
Fixed.
Validate that every type listed in
@phpstan-sealedis a subtype of the annotated class or interface.Invalid entries are reported with the
sealed.notSubtypeerror identifier.Add regression coverage for valid and invalid enum, interface, abstract-class, and final-class sealed subtype declarations, including the reflexive case.
Closes #15204