New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Psalm 5: TypeDoesNotContainType is thrown instead of DocblockTypeContradiction #8932
Comments
I found these snippets: https://psalm.dev/r/9950912ce2<?php
declare(strict_types=1);
/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sonata\AdminBundle\Form\DataTransformer;
use Sonata\AdminBundle\Filter\Model\FilterData;
use Symfony\Component\Form\DataTransformerInterface;
use Symfony\Component\Form\Exception\UnexpectedTypeException;
final class FilterDataTransformer
{
/**
* @param array|null $value
*/
public function reverseTransform($value): null
{
if (null === $value) {
return null;
}
if (!\is_array($value)) {
throw new \Exception('array');
}
return null;
}
}
https://psalm.dev/r/66b46ed7a0<?php
declare(strict_types=1);
/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sonata\AdminBundle\Form\DataTransformer;
use Sonata\AdminBundle\Filter\Model\FilterData;
use Symfony\Component\Form\DataTransformerInterface;
use Symfony\Component\Form\Exception\UnexpectedTypeException;
final class FilterDataTransformer
{
/**
* @param array $value
*/
public function reverseTransform($value): null
{
if (null === $value) {
return null;
}
if (!\is_array($value)) {
throw new \Exception('array');
}
return null;
}
}
|
given the type of the |
I agree it's redundant but i expect it to be redundant with the PHPDoc, and not a "native type". This should be:
That's why I gave the second example (without the union). This is something important for open-source library. |
I added a test about this change. PR is #8999 |
https://psalm.dev/r/76264cec79 is working as expected, so I don't think it's an issue with the MutableUnion but more when parsing the Type. With some dump, I get that the type is an Union of But the TArray should be |
I found these snippets: https://psalm.dev/r/76264cec79<?php
declare(strict_types=1);
/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sonata\AdminBundle\Form\DataTransformer;
use Sonata\AdminBundle\Filter\Model\FilterData;
use Symfony\Component\Form\DataTransformerInterface;
use Symfony\Component\Form\Exception\UnexpectedTypeException;
final class FilterDataTransformer
{
/**
* @param array|null $value
*/
public function reverseTransform($value): null
{
if (\is_array($value)) {
return null;
}
if ($value !== null) {
throw new \Exception('array');
}
return null;
}
}
|
The following example is throwing a TypeDoesNotContainType with Psalm 5 but not with 4
https://psalm.dev/r/9950912ce2
This seems related to the union type since
https://psalm.dev/r/66b46ed7a0
works fine.
The text was updated successfully, but these errors were encountered: