Skip to content

Commit

Permalink
Fix #4310 - prevent literal class check on union
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Oct 12, 2020
1 parent d16c0de commit fcfa746
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
Expand Up @@ -856,7 +856,7 @@ public static function verifyType(
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,
Expand Down
33 changes: 33 additions & 0 deletions tests/Template/ConditionalReturnTypeTest.php
Expand Up @@ -621,6 +621,39 @@ public function get_liste_tdm_by_cod_s(bool $id_only = false): array {
}
}'
],
'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',
]
],
];
}
}

0 comments on commit fcfa746

Please sign in to comment.