Skip to content

Commit

Permalink
Try
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet committed Apr 29, 2024
1 parent 69ecec6 commit 7d78bc8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
17 changes: 7 additions & 10 deletions src/Psalm/Internal/Type/TemplateInferredTypeReplacer.php
Original file line number Diff line number Diff line change
Expand Up @@ -452,17 +452,14 @@ private static function replaceConditional(
null,
false,
false,
) && null === Type::intersectUnionTypes(
new Union([$candidate_atomic_type]),
$conditional_type,
$codebase,
false,
false
)) {
$intersection = Type::intersectUnionTypes(
new Union([$candidate_atomic_type]),
$conditional_type,
$codebase,
);
if (null === $intersection
|| ($candidate_atomic_type instanceof TFloat
&& $intersection->getKey() === 'int')) {
$matching_else_types[] = $candidate_atomic_type;
}
$matching_else_types[] = $candidate_atomic_type;
}
}

Expand Down
10 changes: 10 additions & 0 deletions src/Psalm/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@
use Psalm\Type\Atomic\TNamedObject;
use Psalm\Type\Atomic\TNever;
use Psalm\Type\Atomic\TNonEmptyLowercaseString;
use Psalm\Type\Atomic\TNonEmptyNonspecificLiteralString;
use Psalm\Type\Atomic\TNonEmptyString;
use Psalm\Type\Atomic\TNonFalsyString;
use Psalm\Type\Atomic\TNonspecificLiteralString;
use Psalm\Type\Atomic\TNull;
use Psalm\Type\Atomic\TNumeric;
use Psalm\Type\Atomic\TNumericString;
Expand Down Expand Up @@ -909,6 +911,14 @@ private static function intersectAtomicTypes(
$intersection_atomic = $type_1_atomic;
$wider_type = $type_2_atomic;
$intersection_performed = true;
} elseif (
($type_1_atomic instanceof TNonspecificLiteralString
&& $type_2_atomic instanceof TNonEmptyString)
|| ($type_1_atomic instanceof TNonEmptyString
&& $type_2_atomic instanceof TNonspecificLiteralString)
) {
$intersection_atomic = new TNonEmptyNonspecificLiteralString();
$intersection_performed = true;
}

if ($intersection_atomic
Expand Down

0 comments on commit 7d78bc8

Please sign in to comment.