Remember method/static call expression as truthy/falsey alongside @phpstan-assert-if-true argument narrowing - #5880
Merged
staabm merged 28 commits intoJun 17, 2026
Conversation
staabm
reviewed
Jun 15, 2026
staabm
force-pushed
the
create-pull-request/patch-sxihmja
branch
2 times, most recently
from
June 15, 2026 15:26
ce1888f to
181e6e9
Compare
staabm
force-pushed
the
create-pull-request/patch-sxihmja
branch
3 times, most recently
from
June 15, 2026 23:56
969b695 to
70fb90a
Compare
VincentLanglet
removed their request for review
June 16, 2026 10:32
staabm
marked this pull request as draft
June 16, 2026 12:10
clxmstaab
force-pushed
the
create-pull-request/patch-sxihmja
branch
from
June 16, 2026 12:36
ff8ea80 to
24126c3
Compare
staabm
requested changes
Jun 16, 2026
staabm
left a comment
Contributor
There was a problem hiding this comment.
after this PR the snippet https://phpstan.org/r/9eb23e31-92a3-41e0-9f85-731ee7f3f5b2 runs endless
staabm
requested changes
Jun 16, 2026
staabm
left a comment
Contributor
There was a problem hiding this comment.
fix this endless loop
https://gist.github.com/ondrejmirtes/6ab9c2e53be1c112b3ee1120c6c89aea
…if-true` argument narrowing
- When a function/method/static call carries `@phpstan-assert*` assertions, the
call handlers previously returned only the assert-specified argument narrowing
and skipped `handleDefaultTruthyOrFalseyContext`, so the call expression itself
was not remembered as truthy/falsey in the branch. Re-evaluating it (e.g.
`if (is_readable($p)) { require $p; }`) then yielded `bool` instead of `true`.
- `FuncCallHandler`, `MethodCallHandler` and `StaticCallHandler` now union the
asserts result with the default truthy/falsey narrowing, while preserving the
asserts' original root expression so impossible-check detection is unaffected.
- `ImpossibleCheckTypeHelper` now ignores the self-referential narrowing entry
(the checked call expression itself), which carries no information about
whether the check is redundant — the informative narrowing lives in the
argument entries.
- `RequireFileExistsRule` additionally treats `is_readable`, `is_writable`,
`is_writeable` and `is_executable` (next to `file_exists`/`is_file`) as guards
that prove the path exists, via a named `FILE_EXISTENCE_FUNCTIONS` constant.
- Fixed a genuine `X && !X` bug in the build-only
`OrChainIdenticalComparisonToInArrayRule::getSubjectAndValue()` that the
improved narrowing newly detects.
ondrejmirtes
added a commit
that referenced
this pull request
Jun 20, 2026
…grated handlers Rebasing onto 2.2.x auto-merged the @phpstan-assert-if-true default truthy/falsey narrowing (#5880/#5885) into the migrated FuncCall/Method/StaticCall specify callbacks, but using the old-world local $typeSpecifier instead of the property $this->typeSpecifier — crashing with "Call to a member function handleDefaultTruthyOrFalseyContext() on null" whenever the assert-narrowing path was hit (111 ImpossibleCheckType*/CallToFunctionParameters* test errors).
ondrejmirtes
added a commit
that referenced
this pull request
Jun 30, 2026
…grated handlers Rebasing onto 2.2.x auto-merged the @phpstan-assert-if-true default truthy/falsey narrowing (#5880/#5885) into the migrated FuncCall/Method/StaticCall specify callbacks, but using the old-world local $typeSpecifier instead of the property $this->typeSpecifier — crashing with "Call to a member function handleDefaultTruthyOrFalseyContext() on null" whenever the assert-narrowing path was hit (111 ImpossibleCheckType*/CallToFunctionParameters* test errors).
ondrejmirtes
added a commit
that referenced
this pull request
Jul 6, 2026
…grated handlers Rebasing onto 2.2.x auto-merged the @phpstan-assert-if-true default truthy/falsey narrowing (#5880/#5885) into the migrated FuncCall/Method/StaticCall specify callbacks, but using the old-world local $typeSpecifier instead of the property $this->typeSpecifier — crashing with "Call to a member function handleDefaultTruthyOrFalseyContext() on null" whenever the assert-narrowing path was hit (111 ImpossibleCheckType*/CallToFunctionParameters* test errors).
ondrejmirtes
added a commit
that referenced
this pull request
Jul 16, 2026
…grated handlers Rebasing onto 2.2.x auto-merged the @phpstan-assert-if-true default truthy/falsey narrowing (#5880/#5885) into the migrated FuncCall/Method/StaticCall specify callbacks, but using the old-world local $typeSpecifier instead of the property $this->typeSpecifier — crashing with "Call to a member function handleDefaultTruthyOrFalseyContext() on null" whenever the assert-narrowing path was hit (111 ImpossibleCheckType*/CallToFunctionParameters* test errors).
ondrejmirtes
added a commit
that referenced
this pull request
Jul 28, 2026
…grated handlers Rebasing onto 2.2.x auto-merged the @phpstan-assert-if-true default truthy/falsey narrowing (#5880/#5885) into the migrated FuncCall/Method/StaticCall specify callbacks, but using the old-world local $typeSpecifier instead of the property $this->typeSpecifier — crashing with "Call to a member function handleDefaultTruthyOrFalseyContext() on null" whenever the assert-narrowing path was hit (111 ImpossibleCheckType*/CallToFunctionParameters* test errors).
ondrejmirtes
added a commit
that referenced
this pull request
Jul 28, 2026
…grated handlers Rebasing onto 2.2.x auto-merged the @phpstan-assert-if-true default truthy/falsey narrowing (#5880/#5885) into the migrated FuncCall/Method/StaticCall specify callbacks, but using the old-world local $typeSpecifier instead of the property $this->typeSpecifier — crashing with "Call to a member function handleDefaultTruthyOrFalseyContext() on null" whenever the assert-narrowing path was hit (111 ImpossibleCheckType*/CallToFunctionParameters* test errors).
ondrejmirtes
added a commit
that referenced
this pull request
Jul 28, 2026
…grated handlers Rebasing onto 2.2.x auto-merged the @phpstan-assert-if-true default truthy/falsey narrowing (#5880/#5885) into the migrated FuncCall/Method/StaticCall specify callbacks, but using the old-world local $typeSpecifier instead of the property $this->typeSpecifier — crashing with "Call to a member function handleDefaultTruthyOrFalseyContext() on null" whenever the assert-narrowing path was hit (111 ImpossibleCheckType*/CallToFunctionParameters* test errors).
ondrejmirtes
added a commit
that referenced
this pull request
Jul 28, 2026
…grated handlers Rebasing onto 2.2.x auto-merged the @phpstan-assert-if-true default truthy/falsey narrowing (#5880/#5885) into the migrated FuncCall/Method/StaticCall specify callbacks, but using the old-world local $typeSpecifier instead of the property $this->typeSpecifier — crashing with "Call to a member function handleDefaultTruthyOrFalseyContext() on null" whenever the assert-narrowing path was hit (111 ImpossibleCheckType*/CallToFunctionParameters* test errors).
ondrejmirtes
added a commit
that referenced
this pull request
Jul 28, 2026
…grated handlers Rebasing onto 2.2.x auto-merged the @phpstan-assert-if-true default truthy/falsey narrowing (#5880/#5885) into the migrated FuncCall/Method/StaticCall specify callbacks, but using the old-world local $typeSpecifier instead of the property $this->typeSpecifier — crashing with "Call to a member function handleDefaultTruthyOrFalseyContext() on null" whenever the assert-narrowing path was hit (111 ImpossibleCheckType*/CallToFunctionParameters* test errors).
ondrejmirtes
added a commit
that referenced
this pull request
Jul 28, 2026
…grated handlers Rebasing onto 2.2.x auto-merged the @phpstan-assert-if-true default truthy/falsey narrowing (#5880/#5885) into the migrated FuncCall/Method/StaticCall specify callbacks, but using the old-world local $typeSpecifier instead of the property $this->typeSpecifier — crashing with "Call to a member function handleDefaultTruthyOrFalseyContext() on null" whenever the assert-narrowing path was hit (111 ImpossibleCheckType*/CallToFunctionParameters* test errors).
ondrejmirtes
added a commit
that referenced
this pull request
Jul 28, 2026
…grated handlers Rebasing onto 2.2.x auto-merged the @phpstan-assert-if-true default truthy/falsey narrowing (#5880/#5885) into the migrated FuncCall/Method/StaticCall specify callbacks, but using the old-world local $typeSpecifier instead of the property $this->typeSpecifier — crashing with "Call to a member function handleDefaultTruthyOrFalseyContext() on null" whenever the assert-narrowing path was hit (111 ImpossibleCheckType*/CallToFunctionParameters* test errors).
ondrejmirtes
added a commit
that referenced
this pull request
Jul 28, 2026
…grated handlers Rebasing onto 2.2.x auto-merged the @phpstan-assert-if-true default truthy/falsey narrowing (#5880/#5885) into the migrated FuncCall/Method/StaticCall specify callbacks, but using the old-world local $typeSpecifier instead of the property $this->typeSpecifier — crashing with "Call to a member function handleDefaultTruthyOrFalseyContext() on null" whenever the assert-narrowing path was hit (111 ImpossibleCheckType*/CallToFunctionParameters* test errors).
ondrejmirtes
added a commit
that referenced
this pull request
Jul 28, 2026
…grated handlers Rebasing onto 2.2.x auto-merged the @phpstan-assert-if-true default truthy/falsey narrowing (#5880/#5885) into the migrated FuncCall/Method/StaticCall specify callbacks, but using the old-world local $typeSpecifier instead of the property $this->typeSpecifier — crashing with "Call to a member function handleDefaultTruthyOrFalseyContext() on null" whenever the assert-narrowing path was hit (111 ImpossibleCheckType*/CallToFunctionParameters* test errors).
ondrejmirtes
added a commit
that referenced
this pull request
Jul 28, 2026
…grated handlers Rebasing onto 2.2.x auto-merged the @phpstan-assert-if-true default truthy/falsey narrowing (#5880/#5885) into the migrated FuncCall/Method/StaticCall specify callbacks, but using the old-world local $typeSpecifier instead of the property $this->typeSpecifier — crashing with "Call to a member function handleDefaultTruthyOrFalseyContext() on null" whenever the assert-narrowing path was hit (111 ImpossibleCheckType*/CallToFunctionParameters* test errors).
ondrejmirtes
added a commit
that referenced
this pull request
Jul 28, 2026
…grated handlers Rebasing onto 2.2.x auto-merged the @phpstan-assert-if-true default truthy/falsey narrowing (#5880/#5885) into the migrated FuncCall/Method/StaticCall specify callbacks, but using the old-world local $typeSpecifier instead of the property $this->typeSpecifier — crashing with "Call to a member function handleDefaultTruthyOrFalseyContext() on null" whenever the assert-narrowing path was hit (111 ImpossibleCheckType*/CallToFunctionParameters* test errors).
ondrejmirtes
added a commit
that referenced
this pull request
Jul 28, 2026
…grated handlers Rebasing onto 2.2.x auto-merged the @phpstan-assert-if-true default truthy/falsey narrowing (#5880/#5885) into the migrated FuncCall/Method/StaticCall specify callbacks, but using the old-world local $typeSpecifier instead of the property $this->typeSpecifier — crashing with "Call to a member function handleDefaultTruthyOrFalseyContext() on null" whenever the assert-narrowing path was hit (111 ImpossibleCheckType*/CallToFunctionParameters* test errors).
ondrejmirtes
added a commit
that referenced
this pull request
Jul 30, 2026
…grated handlers Rebasing onto 2.2.x auto-merged the @phpstan-assert-if-true default truthy/falsey narrowing (#5880/#5885) into the migrated FuncCall/Method/StaticCall specify callbacks, but using the old-world local $typeSpecifier instead of the property $this->typeSpecifier — crashing with "Call to a member function handleDefaultTruthyOrFalseyContext() on null" whenever the assert-narrowing path was hit (111 ImpossibleCheckType*/CallToFunctionParameters* test errors).
ondrejmirtes
added a commit
that referenced
this pull request
Jul 30, 2026
…grated handlers Rebasing onto 2.2.x auto-merged the @phpstan-assert-if-true default truthy/falsey narrowing (#5880/#5885) into the migrated FuncCall/Method/StaticCall specify callbacks, but using the old-world local $typeSpecifier instead of the property $this->typeSpecifier — crashing with "Call to a member function handleDefaultTruthyOrFalseyContext() on null" whenever the assert-narrowing path was hit (111 ImpossibleCheckType*/CallToFunctionParameters* test errors).
ondrejmirtes
added a commit
that referenced
this pull request
Jul 30, 2026
…grated handlers Rebasing onto 2.2.x auto-merged the @phpstan-assert-if-true default truthy/falsey narrowing (#5880/#5885) into the migrated FuncCall/Method/StaticCall specify callbacks, but using the old-world local $typeSpecifier instead of the property $this->typeSpecifier — crashing with "Call to a member function handleDefaultTruthyOrFalseyContext() on null" whenever the assert-narrowing path was hit (111 ImpossibleCheckType*/CallToFunctionParameters* test errors).
ondrejmirtes
added a commit
that referenced
this pull request
Jul 30, 2026
…grated handlers Rebasing onto 2.2.x auto-merged the @phpstan-assert-if-true default truthy/falsey narrowing (#5880/#5885) into the migrated FuncCall/Method/StaticCall specify callbacks, but using the old-world local $typeSpecifier instead of the property $this->typeSpecifier — crashing with "Call to a member function handleDefaultTruthyOrFalseyContext() on null" whenever the assert-narrowing path was hit (111 ImpossibleCheckType*/CallToFunctionParameters* test errors).
ondrejmirtes
added a commit
that referenced
this pull request
Jul 30, 2026
…grated handlers Rebasing onto 2.2.x auto-merged the @phpstan-assert-if-true default truthy/falsey narrowing (#5880/#5885) into the migrated FuncCall/Method/StaticCall specify callbacks, but using the old-world local $typeSpecifier instead of the property $this->typeSpecifier — crashing with "Call to a member function handleDefaultTruthyOrFalseyContext() on null" whenever the assert-narrowing path was hit (111 ImpossibleCheckType*/CallToFunctionParameters* test errors).
ondrejmirtes
added a commit
that referenced
this pull request
Jul 30, 2026
…grated handlers Rebasing onto 2.2.x auto-merged the @phpstan-assert-if-true default truthy/falsey narrowing (#5880/#5885) into the migrated FuncCall/Method/StaticCall specify callbacks, but using the old-world local $typeSpecifier instead of the property $this->typeSpecifier — crashing with "Call to a member function handleDefaultTruthyOrFalseyContext() on null" whenever the assert-narrowing path was hit (111 ImpossibleCheckType*/CallToFunctionParameters* test errors).
ondrejmirtes
added a commit
that referenced
this pull request
Jul 30, 2026
…grated handlers Rebasing onto 2.2.x auto-merged the @phpstan-assert-if-true default truthy/falsey narrowing (#5880/#5885) into the migrated FuncCall/Method/StaticCall specify callbacks, but using the old-world local $typeSpecifier instead of the property $this->typeSpecifier — crashing with "Call to a member function handleDefaultTruthyOrFalseyContext() on null" whenever the assert-narrowing path was hit (111 ImpossibleCheckType*/CallToFunctionParameters* test errors).
ondrejmirtes
added a commit
that referenced
this pull request
Jul 31, 2026
…grated handlers Rebasing onto 2.2.x auto-merged the @phpstan-assert-if-true default truthy/falsey narrowing (#5880/#5885) into the migrated FuncCall/Method/StaticCall specify callbacks, but using the old-world local $typeSpecifier instead of the property $this->typeSpecifier — crashing with "Call to a member function handleDefaultTruthyOrFalseyContext() on null" whenever the assert-narrowing path was hit (111 ImpossibleCheckType*/CallToFunctionParameters* test errors).
ondrejmirtes
added a commit
that referenced
this pull request
Jul 31, 2026
…grated handlers Rebasing onto 2.2.x auto-merged the @phpstan-assert-if-true default truthy/falsey narrowing (#5880/#5885) into the migrated FuncCall/Method/StaticCall specify callbacks, but using the old-world local $typeSpecifier instead of the property $this->typeSpecifier — crashing with "Call to a member function handleDefaultTruthyOrFalseyContext() on null" whenever the assert-narrowing path was hit (111 ImpossibleCheckType*/CallToFunctionParameters* test errors).
ondrejmirtes
added a commit
that referenced
this pull request
Jul 31, 2026
…grated handlers Rebasing onto 2.2.x auto-merged the @phpstan-assert-if-true default truthy/falsey narrowing (#5880/#5885) into the migrated FuncCall/Method/StaticCall specify callbacks, but using the old-world local $typeSpecifier instead of the property $this->typeSpecifier — crashing with "Call to a member function handleDefaultTruthyOrFalseyContext() on null" whenever the assert-narrowing path was hit (111 ImpossibleCheckType*/CallToFunctionParameters* test errors).
ondrejmirtes
added a commit
that referenced
this pull request
Aug 4, 2026
…grated handlers Rebasing onto 2.2.x auto-merged the @phpstan-assert-if-true default truthy/falsey narrowing (#5880/#5885) into the migrated FuncCall/Method/StaticCall specify callbacks, but using the old-world local $typeSpecifier instead of the property $this->typeSpecifier — crashing with "Call to a member function handleDefaultTruthyOrFalseyContext() on null" whenever the assert-narrowing path was hit (111 ImpossibleCheckType*/CallToFunctionParameters* test errors).
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.
similar to #5885 but for
MethodCallandStaticCall