Repository navigation
Conversation
…self `$map = new WeakAnalysingMap(); $map->set($map);` with `@param TOwner $owner` puts `WeakAnalysingMap<TOwner>` as a lower bound on the `new` site's own `TOwner`. Resolving it substituted the site's default for the inner `TOwner`, so `$map` became `WeakAnalysingMap<WeakAnalysingMap<object>>` - and then no longer matched the parameter it was inferred from. A bound that contains the argument it bounds says nothing about it. Skip it, so the argument falls back to what 2.2 inferred. Closes phpstan/phpstan#15434
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.
Closes phpstan/phpstan#15434
Since 2.3.0, passing an object whose template argument is still being inferred to its own method makes the argument refer to itself:
$map->set($map)recordsWeakAnalysingMap<TOwner>as a lower bound on thenewsite's ownTOwner. WhenTemplateArgumentSolverresolves that bound, the innerTOwneris the site that is being resolved, soresolveKey()returns its delegate (object). The site then resolves toWeakAnalysingMap<object>, and$mapno longer matches the parameter it was inferred from.A lower bound that contains the argument it bounds carries no information about it.
resolveObservation()now skips such bounds, so the argument falls back to its bound (object), as on 2.2.17. Bounds from other calls still count:$map->set(new stdClass())still infersWeakAnalysingMap<stdClass>.tests/PHPStan/Rules/Methods/data/bug-15434.phpis the issue's code. The test fails without the change inTemplateArgumentSolver.php(it reports theargument.typeerror from the issue) and passes with it.TemplateArgumentSolverhas no turbo mirror, soturbo-ext/is unchanged.make testspasses, and phpcs is clean on the changed files.