1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-21 21:31:13 +01:00

Don’t check classes if literal strings are allowed

Fixes #3538
This commit is contained in:
Matthew Brown 2020-06-06 19:31:42 -04:00
parent 4f87cca55b
commit 74a34f066c
2 changed files with 30 additions and 0 deletions

View File

@ -785,6 +785,7 @@ class ArgumentAnalyzer
foreach ($param_type->getAtomicTypes() as $param_type_part) {
if ($param_type_part instanceof TClassString
&& $input_expr instanceof PhpParser\Node\Scalar\String_
&& !$param_type->getLiteralStrings()
) {
if (ClassLikeAnalyzer::checkFullyQualifiedClassLikeName(
$statements_analyzer,

View File

@ -520,6 +520,35 @@ class ConditionalReturnTypeTest extends TestCase
return $c->get("t", null);
}'
],
'literalStringIsNotAClassString' => [
'<?php
interface SerializerInterface
{
/**
* Deserializes the given data to the specified type.
*
* @psalm-template TClass
* @psalm-template TType as \'array\'|class-string<TClass>
* @psalm-param TType $type
* @psalm-return (
* TType is \'array\'
* ? array
* : TClass
* )
*
* @return mixed
*/
public function deserialize(string $data, string $type);
}
function foo(SerializerInterface $i, string $data): Exception {
return $i->deserialize($data, Exception::class);
}
function bar(SerializerInterface $i, string $data): array {
return $i->deserialize($data, \'array\');
}'
],
];
}
}