Skip to content

Fix phpstan/phpstan#13981: Assignment inside match statement no longer recognized#5120

Open
phpstan-bot wants to merge 3 commits intophpstan:2.1.xfrom
phpstan-bot:create-pull-request/patch-hynebfv
Open

Fix phpstan/phpstan#13981: Assignment inside match statement no longer recognized#5120
phpstan-bot wants to merge 3 commits intophpstan:2.1.xfrom
phpstan-bot:create-pull-request/patch-hynebfv

Conversation

@phpstan-bot
Copy link
Collaborator

@phpstan-bot phpstan-bot commented Mar 2, 2026

staabm and others added 3 commits March 2, 2026 06:32
- Variable assignments in match arm conditions (e.g. `is_dir($baseDir = ...)`)
  were lost after commit 3beb8c6 replaced processExprNode with filterByTruthyValue
- filterByTruthyValue only narrows types without walking the AST, so assignments
  within condition expressions were not discovered for the arm body scope
- Fix transfers newly-defined variables from the condition processing scope to
  the body scope after applying truthiness filtering
- New regression test in tests/PHPStan/Rules/Variables/data/bug-13981.php

Closes phpstan/phpstan#13981
@VincentLanglet VincentLanglet self-assigned this Mar 3, 2026
@VincentLanglet VincentLanglet requested a review from staabm March 4, 2026 17:19
@VincentLanglet VincentLanglet removed their assignment Mar 4, 2026
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