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
Compute ConstantArrayType sealed-shape isSuperTypeOf() reasons lazily via IsSuperTypeOfResult closures
- Add an optional `list<Closure(): string> $lazyReasons` channel to `IsSuperTypeOfResult`
plus a `getReasons()` accessor that materializes and de-duplicates them; `and()`, `or()`,
`decorateReasons()`, `extremeIdentity()`, `maxMin()`, `lazyMaxMin()`, `negate()` and
`toAcceptsResult()` all propagate the lazy reasons untouched.
- `ConstantArrayType::isSuperTypeOf()` now passes the "Sealed array shapes … cannot be
intersected" explanation as a lazy closure instead of eagerly calling `describe()` on both
shapes for every sealed-vs-sealed comparison. On `tests/bench/data/bug-7581.php` this
removed 22.5k wasted `describe()` builds (the reason was never rendered) and cut analysis
time ~35% (≈693ms → ≈452ms in-process), erasing the regression from the "reasons" batch.
- Materialize the lazy reasons at the render sites that surface them as tips:
`TypeCombinator::intersect()` (both NeverType-with-reason branches),
`InitializerExprTypeResolver::resolveIdenticalType()`, `ImpossibleCheckTypeHelper` and
`ImpossibleInstanceOfRule`, so error output is unchanged.
- Probed the sibling `accepts()` / `AcceptsResult` describe-based reasons in `ConstantArrayType`:
they only run on genuine acceptance failures (0 builds on the benchmark), so they are not
part of this regression and were left eager. The parallel `ObjectType` reasons were already
addressed separately (0c88c32, 4be03a5).
// The expensive describe()-based reason must not be built eagerly during the
1047
+
// isSuperTypeOf() hot path - it is only materialized on demand via getReasons().
1048
+
$this->assertSame([], $result->reasons);
1049
+
$this->assertSame([
1050
+
'Sealed array shapes array{foo: int} and array{bar: string} cannot be intersected. Unseal at least one of them with ... syntax. Learn more: https://phpstan.org/blog/phpstan-2-2-unsealed-array-shapes-safer-array-keys',
0 commit comments