Repository navigation
Conversation
…pe is tracked MutatingScope::applySpecifiedTypes() takes the base type of a narrowing from the tracked expression holders. An expression can be tracked with its PHPDoc type but not with a native one, for example `$s['projects']` after `$has = isset($s['projects']); if (!$has) return;`, where the conditional holder of `$has` only carries the PHPDoc type. The native result of a sure-not narrowing then fell back to the PHPDoc result, so `$s['projects'] !== []` (which foreach applies to its iteratee) made the native type `non-empty-list<string>` and `$p` natively `string`. With treatPhpDocTypesAsCertain: false, is_string($p) was then reported as always true. When only the PHPDoc type is tracked, the native base is now read from the scope, as it already is for untracked expressions. 2.2.17 read it through getNativeType() in removeTypeFromExpression(). Closes phpstan/phpstan#15404
Contributor
|
please stop flooding the repo with more pull requests. you should learn from feedback on your already opened ones and open new ones after some of them landed. |
Contributor
Author
|
Understood, sorry about the volume. I won't open any more PRs here until the open ones have been reviewed, and I'll work through the feedback on them first. |
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.
Fixes phpstan/phpstan#15404. Thanks @zajca for the report and the reproducer.
MutatingScope::applySpecifiedTypes()reads the base type of a narrowing from the tracked expression holders. An expression can be tracked with its PHPDoc type and have no native holder. In the issue,$has = isset($s['projects']); if (!$has) return;applies the conditional holder of$has, which tracks$s['projects']aslist<string>in the PHPDoc types only. The native type is still read through$s(array), so it ismixed.For a sure-not narrowing, the native result then fell back to the PHPDoc result when no native holder was tracked.
foreachnarrows its iteratee with$s['projects'] !== [], so the native type becamenon-empty-list<string>and$pwas nativelystring. WithtreatPhpDocTypesAsCertain: false,is_string($p)was reported as always true. The inlineif (!isset($s['projects']))form tracks$s['projects']with a native holder too (mixed~null), so it was not affected. 2.2.17 read the native base withgetNativeType()inremoveTypeFromExpression().When only the PHPDoc type is tracked, the native base is now read from the scope with
getCurrentTypesOfSpecifiedExpr(), the same way untracked expressions already get both types. Inside the loop$s['projects']is nativelymixed~array{}and$pismixed, as on 2.2.17. The PHPDoc types do not change.MutatingScopeis shadowed by turbo-ext, soMutatingScope.cppgets the same change. A separate commit bumps the expected turbo version.ImpossibleCheckTypeFunctionCallRuleWithUncertainPhpDocTypesTest::testBug15404analyses the issue's code and expects no errors. Without the fix it fails withCall to function is_string() with string will always evaluate to true.on line 13. The full test suite passes with and without the turbo extension loaded,smoke.phpandsignature-parity.phppass, and phpcs is clean on the changed files.Closes phpstan/phpstan#15404