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 042cc06 commit dfa8854
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,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
Original file line number Diff line number Diff line change
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 dfa8854

Please sign in to comment.