mirror of
https://github.com/danog/psalm.git
synced 2025-01-22 05:41:20 +01:00
Fix #4310 - prevent literal class check on union
This commit is contained in:
parent
d16c0de872
commit
fcfa746ba8
@ -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,
|
||||
|
@ -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',
|
||||
]
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user