return type and `hasOffset` array shape
staabm opened this issue · 3 comments
staabm commented
Bug report
phpstan already knows about the offsets a array has after certain checks, e.g. array_key_exists.
this knowledge should be used for the return-type inference.
Code snippet that reproduces the problem
https://phpstan.org/r/46e25e3e-20dd-4248-ab74-7ee32e73bbf2
Expected output
no error
phpstan-bot commented
@staabm After the latest commit in 1.6.x, PHPStan now reports different result with your code snippet:
@@ @@
-15: Dumped type: array&hasOffset('schemaVersion')
-16: Method HelloWorld::sayHello() should return array{schemaVersion: mixed}|null but returns array.
+15: Dumped type: array&hasOffset('schemaVersion')Full report
| Line | Error |
|---|---|
| 15 | Dumped type: array&hasOffset('schemaVersion') |
github-actions commented
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.