Skip to content

Preserve source types during destructuring assignments - #6760

Open
Gabrieljr42 wants to merge 2 commits into
phpstan:2.3.xfrom
Gabrieljr42:fix/destructuring-rhs-types
Open

Gabrieljr42 wants to merge 2 commits into
phpstan:2.3.xfrom
Gabrieljr42:fix/destructuring-rhs-types

Conversation

@Gabrieljr42

@Gabrieljr42 Gabrieljr42 commented Oct 17, 2026 •

Copy link
Copy Markdown

Fixes phpstan/phpstan#15091.
Also covers phpstan/phpstan#15181.

When an earlier destructuring target overwrites the source variable, later targets must still use the original source type. Capture both the PHPDoc and native source types before assigning any items, in the PHP and Turbo implementations.

The regression covers positional and keyed assignments, nested destructuring, skipped slots, callable values and a source variable reused in a later target.

Validation on PHP 8.3.6:

  • The new regression and three existing destructuring fixtures pass with and without Turbo.
  • The native Turbo extension builds successfully and activates with the matching generated version.
  • PHP syntax and diff checks pass.
  • The CI workflows for tests, lint, static analysis, E2E, benchmarks and reflection all pass.

The Compile PHAR integration matrix currently stops during Composer installation in the two phpstan-laravel jobs, before running the analyzer. The external integration lock pins Laravel 13.35.0, PHPStan 2.3.1 and structarmed 0.18.11, while the updated fixture requires at least Laravel 13.38.0, PHPStan 2.3.2 and structarmed 0.19.3. See the installation failure. The integration lock fix is submitted separately in phpstan/phpstan#15536, where both phpstan-laravel integration jobs now pass in CI. With that fix, the pinned fixture installs and all 3,031 integration tests plus static analysis pass locally on PHP 8.5.12 using this PR’s PHAR and matching Turbo artifacts. No CI check has been disabled or relaxed in this PR.

I used AI assistance for the implementation, tests and branch update.

@Gabrieljr42

Copy link
Copy Markdown
Author

I checked the two E2E failures. The parse-error case has the same "expected 1, got 0" failure on the current 2.3.x base.

The other job stopped while downloading the bashunit checksum, before running its tests. Both local full suites passed, with and without Turbo.

@Gabrieljr42
Gabrieljr42 force-pushed the fix/destructuring-rhs-types branch from 45bd1bb to 578a76d Compare October 25, 2026 15:00
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.

Destructuring reassignment loses type info

1 participant