-
Notifications
You must be signed in to change notification settings - Fork 574
Invalidate maybe-impure function return values after impure method/static calls #5667
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
phpstan-bot
wants to merge
11
commits into
phpstan:2.1.x
Choose a base branch
from
phpstan-bot:create-pull-request/patch-vf3uivq
base: 2.1.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+240
−80
Open
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
e9ba032
Invalidate maybe-impure function return values after impure method/st…
VincentLanglet 923d2b1
Prevent type narrowing of expressions containing impure calls
phpstan-bot e731e88
Remove redundant early returns subsumed by expressionContainsNonPureCall
phpstan-bot 452a3c8
Return TrinaryLogic from expressionContainsNonPureCall
phpstan-bot 7687df3
Add tests for impure closures and arrow functions
phpstan-bot 1fd7cb8
Revert "Return TrinaryLogic from expressionContainsNonPureCall"
staabm 968e01a
Update TypeSpecifier.php
staabm aadf81a
Do not treat unknown functions as non-pure in sub-expression purity c…
phpstan-bot 9d80f7d
Add non-regression test for unknown function sub-expression handling
phpstan-bot 5ef8c3d
Replace unit test with NSRT integration test for FAUX_FUNCTION handling
phpstan-bot 159e29a
Restore unit test for unknown function sub-expression handling
phpstan-bot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could this be tested via StrContainingTypeSpecifyingExtension with a str-containing function instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Replaced the contrived
TypeSpecifierTest::testUnknownFunctionSubExpressionDoesNotPreventNarrowingunit test (which manually builtcount(FAUX_FUNCTION($foo))AST nodes) with an NSRT integration test innon-empty-string-str-containing-fns.phpthat exercisesstr_containswith anon-empty-stringneedle — which triggers theFAUX_FUNCTIONrootExpr path inStrContainingTypeSpecifyingExtension. The test verifies narrowing works correctly across two successivestr_containscalls. All 12071 tests pass, PHPStan self-analysis clean, CS clean.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the newly added test does not fail when reverting aadf81a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pushed. The fix restores the
TypeSpecifierTest::testUnknownFunctionSubExpressionDoesNotPreventNarrowingunit test which directly exercises the unknown-function-in-sub-expression code path by callingTypeSpecifier::create()withcount(FAUX_FUNCTION($foo)). I verified that this test correctly fails when reverting commit aadf81a (empty SpecifiedTypes instead of narrowed type) and passes with the fix in place. The NSRT test innon-empty-string-str-containing-fns.phpwas removed since it only narrows a Variable and never touchesexpressionContainsNonPureCallwith unknown functions.