phpstan: False positive with ext-ds
Bug report
This only started on phpstan 0.12.8.
Code snippet that reproduces the problem
/** @var \Ds\Map<PaymentGroupId, array<Payment>> $paymentsByGroup */
$paymentsByGroup = new \Ds\Map();
$paymentGroup = $paymentsByGroup->get($paymentGroupId, []);
$paymentGroup[] = Payment::fromValues(...);
The last line triggers this error:
Cannot access an offset on array<App\Module\PaymentRegistry\Domain\PaymentGroup\ValueObject\Payment>|TDefault.
Something is wrong here - TDefault is a generic type in Map::get() so it makes no sense that the error refers to it. Also it is actually an array in this case which means that $paymentGroup will always be an array.
Expected output
no error
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 27 (25 by maintainers)
Meh. I forked phpstan-src, added it to packagist and debugged with that. Your suggested fix works just fine. I added it to https://github.com/phpstan/phpstan-src/pull/126.
I did the
replace/providedance previously with phpstan-shim and it’s something I don’t want to ever touch again, it’s a huge can of worms.@ondrejmirtes as we’re talking about it already, what is the preferred way to run phpstan fork within my project? I remember I wanted to debug something month ago or so but had no idea how to require my version of phpstan since it uses phar?
EDIT: @enumag I see we have the same issue 😄