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 78e526c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
18 changes: 7 additions & 11 deletions src/Psalm/Internal/Type/TemplateInferredTypeReplacer.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use Psalm\Type\Atomic;
use Psalm\Type\Atomic\TClassString;
use Psalm\Type\Atomic\TConditional;
use Psalm\Type\Atomic\TFloat;
use Psalm\Type\Atomic\TInt;
use Psalm\Type\Atomic\TIterable;
use Psalm\Type\Atomic\TKeyOf;
Expand Down Expand Up @@ -452,17 +451,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
9 changes: 9 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,13 @@ 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 78e526c

Please sign in to comment.