Skip to content

Fix compatibility on optional key on array dim fetch to be Mixed on phpstan patch 2.1.x-dev#8008

Merged
samsonasik merged 1 commit into
mainfrom
fix-resolve-arrayd-dim-fetch
May 24, 2026
Merged

Fix compatibility on optional key on array dim fetch to be Mixed on phpstan patch 2.1.x-dev#8008
samsonasik merged 1 commit into
mainfrom
fix-resolve-arrayd-dim-fetch

Conversation

@samsonasik
Copy link
Copy Markdown
Member

@samsonasik samsonasik commented May 24, 2026

@VincentLanglet this should fixes rectorphp/rector#9770

1) Rector\Tests\TypeDeclaration\Rector\ClassMethod\AddMethodCallBasedStrictParamTypeRector\AddMethodCallBasedStrictParamTypeRectorTest::test#20 with data ('/home/runner/work/phpstan/php...hp.inc')
Failed on fixture file "skip_native_optional_array_shape.php.inc"
Failed asserting that string matches format description.
--- Expected
+++ Actual
@@ @@
         $this->doBar($shape['dirname']); // dirname is only conditionally returned
     }
 
-    private function doBar($param) {
+    private function doBar(string $param) {
 
     }
 }

The other notice is only union order so I think we can just update the fixture once next phpstan released.

-    public static function extension($filename): array|string
+    public static function extension($filename): string|array

step to reproduce:

  1. Temporary change composer.json phpstan/phpstan require to 2.1.x-dev
  2. Run unit test

@samsonasik
Copy link
Copy Markdown
Member Author

All green 🎉 @TomasVotruba let's merge ;)

@samsonasik samsonasik merged commit b095655 into main May 24, 2026
78 checks passed
@samsonasik samsonasik deleted the fix-resolve-arrayd-dim-fetch branch May 24, 2026 23:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

resolveArrayDimFetchType behavior will slightly change with next phpstan version

1 participant