Compatibility fixes for PHPStan 2.1.52#351
Merged
Conversation
Two new errors surface on PHPStan 2.1.52 (CI uses `composer update`, so any new PR pulls the latest): - tests/Cache/UsageCacheStorageTest.php:82 — `staticMethod.alreadyNarrowedType` on `assertCount(2, $restored)`. The narrowing comes from a regression in 2.1.52 where a nested foreach over `non-empty-list<T>` is collapsed to an exact-count tuple. Reported upstream: phpstan/phpstan#14543 - tests/Rule/DeadCodeRuleTest.php:1373 — `offsetAccess.nonArray` for destructuring `$error->getMetadata()`. Annotate `$metadata` with the shape the rule actually emits so destructuring is well-typed. Lockfile bumped to 2.1.52 to match what CI runs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two errors surface on PHPStan 2.1.52 (CI uses
composer update, so any new PR pulls the latest):tests/Cache/UsageCacheStorageTest.php:82—staticMethod.alreadyNarrowedTypeonassertCount(2, $restored). The narrowing is a regression in 2.1.52: nestedforeachover anon-empty-list<T>collapses to an exact-count tuple instead ofnon-empty-list<T>. Bisected to 2.1.51 → 2.1.52. Reported upstream: Since 2.1.52 nested foreach over non-empty-list<T> narrows accumulated array to exact count phpstan/phpstan#14543. Suppressed locally with@phpstan-ignorereferencing the issue.tests/Rule/DeadCodeRuleTest.php:1373—offsetAccess.nonArrayfor destructuring$error->getMetadata(). The previous floating/** @var BlackMember *///** @var bool */tags don't help with destructuring; replaced with a@varon$metadatadeclaring the shape the rule actually emits.Lockfile bumped to 2.1.52 to match what CI runs.