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

Fix #4310 - prevent literal class check on union

This commit is contained in:
Matt Brown 2020-10-12 14:45:11 -04:00
parent d16c0de872
commit fcfa746ba8
2 changed files with 34 additions and 1 deletions

View File

@ -856,7 +856,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()
&& $param_type->isSingle()
) {
if (ClassLikeAnalyzer::checkFullyQualifiedClassLikeName(
$statements_analyzer,

View File

@ -621,6 +621,39 @@ class ConditionalReturnTypeTest extends TestCase
}
}'
],
'stringOrClassStringT' => [
'<?php
class A {}
/**
* @template T
* @param string|class-string<T> $name
* @return ($name is class-string ? T : mixed)
*/
function get(string $name) {
return;
}
$lowercase_a = "a";
/** @var class-string $class_string */
$class_string = "b";
/** @psalm-suppress MixedAssignment */
$expect_mixed = get($lowercase_a);
$expect_object = get($class_string);
$expect_a_object = get(A::class);
/** @psalm-suppress MixedAssignment */
$expect_mixed_from_literal = get("LiteralDirect");',
[
'$expect_mixed' => 'mixed',
'$expect_object' => 'object',
'$expect_a_object' => 'A',
'$expect_mixed_from_literal' => 'mixed',
]
],
];
}
}