🌐 US-Proxy
class="logged-out env-production page-responsive" style="word-wrap: break-word;" >
Skip to content

Remember method/static call expression as truthy/falsey alongside @phpstan-assert-if-true argument narrowing - #5880

Merged
staabm merged 28 commits into
phpstan:2.2.xfrom
phpstan-bot:create-pull-request/patch-sxihmja
Jun 17, 2026
Merged

Remember method/static call expression as truthy/falsey alongside @phpstan-assert-if-true argument narrowing#5880
staabm merged 28 commits into
phpstan:2.2.xfrom
phpstan-bot:create-pull-request/patch-sxihmja

Conversation

@phpstan-bot

@phpstan-bot phpstan-bot commented Jun 15, 2026

Copy link
Copy Markdown
Collaborator

similar to #5885 but for MethodCall and StaticCall

Comment thread build/PHPStan/Build/OrChainIdenticalComparisonToInArrayRule.php
@staabm
staabm force-pushed the create-pull-request/patch-sxihmja branch 2 times, most recently from ce1888f to 181e6e9 Compare June 15, 2026 15:26
@staabm
staabm requested a review from VincentLanglet June 15, 2026 15:31
@staabm
staabm force-pushed the create-pull-request/patch-sxihmja branch 3 times, most recently from 969b695 to 70fb90a Compare June 15, 2026 23:56
@VincentLanglet
VincentLanglet removed their request for review June 16, 2026 10:32
@staabm
staabm marked this pull request as draft June 16, 2026 12:10
@clxmstaab
clxmstaab force-pushed the create-pull-request/patch-sxihmja branch from ff8ea80 to 24126c3 Compare June 16, 2026 12:36

@staabm staabm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after this PR the snippet https://phpstan.org/r/9eb23e31-92a3-41e0-9f85-731ee7f3f5b2 runs endless

@staabm staabm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

phpstan-bot and others added 16 commits June 16, 2026 21:53
…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.
@staabm
staabm merged commit ca1918c into phpstan:2.2.x Jun 17, 2026
672 of 674 checks passed
@staabm
staabm deleted the create-pull-request/patch-sxihmja branch June 17, 2026 08:03
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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants