Repository navigation
Expand the params of a final class's method with its static as the class itself - #14203
Conversation
✅ Performance: unchanged · Types: decreased
How to read this table
✅ tempest: issues +10 −17Memory 895 → 895 MB (<0.1 %) · Wall 26.7 → 26.8 s (+0.5 %) Weighted 10 528 → 10 507 (−21, −0.20 %): L3 −7
Added (10)
Removed (17)
head 05b980e · base 2da2040 (merge-base) · workflow run |
|
Rebased onto master (78d192b). The only conflict was in |
991c3dd to
95a179e
Compare
orklah
left a comment
There was a problem hiding this comment.
Thanks for this. The tests are good and the false positive is real, but the fix is at the wrong level: the
Query&static comes from FunctionLikeAnalyzer, which expands every param type with final: false
(TypeExpander::expandUnion(..., $param_type->hasConditional(), false, true, false, true)), while $this of a
final class is already a plain Query. Teaching the comparators that X&static equals X then leaks into the
PHP signature checks, which is why MethodComparator needs replacesStaticWithItsClass() to undo it before 8.5.
Passing the class's finality there instead:
$param_type = TypeExpander::expandUnion(
$codebase,
$param_type,
$context->self,
$context->self,
$this->getParentFQCLN(),
true,
$param_type->hasConditional(),
$context->self !== null
&& $codebase->classlike_storage_provider->has($context->self)
&& $codebase->classlike_storage_provider->get($context->self)->final,
true,
false,
true,
);makes finalClassForwardsItsClosureOfStaticParam, the generic and enum variants and a callable($this) param
(the Tempest Timelock case) pass locally, without touching the comparators. Could you move the fix there, drop
the comparator changes, isSealedClass() and the MethodComparator guard, and keep your tests? The Config
baseline entry is a static property, handled separately in #14351.
|
Rebased onto master (2da2040) and squashed into one commit. The conflict was with 80bc820, which now expands |
795261b to
05b980e
Compare
orklah
left a comment
There was a problem hiding this comment.
Thanks @shu-chen-dot-ca!
A final class or enum forwarding its own
Closure(static)(orcallable(list<static>)) param to another method of$this, or calling it with$this, gets a falseArgumentTypeCoercion.Before
After
The params of a method are now expanded with the class's finality, so
staticin them is the class itself in a final class, as$thisalready is. Static of a non-final class is still checked (nonFinalClassInstancePassedToItsStaticParam).Fixes #13519