Skip to content

Commit 7b4ab31

Browse files
committed
Revert & fix
1 parent daca1c7 commit 7b4ab31

File tree

5 files changed

+12
-34
lines changed

5 files changed

+12
-34
lines changed

src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArrayFunctionArgumentsAnalyzer.php

+3
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,9 @@ public static function handleSplice(
355355
if (($array_arg_type = $statements_analyzer->node_data->getType($array_arg))
356356
&& $array_arg_type->hasArray()
357357
) {
358+
/**
359+
* @var TArray|TKeyedArray
360+
*/
358361
$array_type = $array_arg_type->getArray();
359362
if ($generic_array_type = ArrayType::infer($array_type)) {
360363
$array_size = $generic_array_type->count;

src/Psalm/Internal/Type/ArrayType.php

+2-4
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,8 @@ public function __construct(public Union $key, public Union $value, public bool
2323

2424
/**
2525
* @return (
26-
* $type is TKeyedArray ? self : (
27-
* $type is TNonEmptyArray ? self : (
28-
* $type is TArray ? self : null
29-
* )
26+
* $type is TArrayKey ? self : (
27+
* $type is TArray ? self : null
3028
* )
3129
* )
3230
*/

src/Psalm/Internal/Type/TemplateInferredTypeReplacer.php

-6
Original file line numberDiff line numberDiff line change
@@ -455,12 +455,6 @@ private static function replaceConditional(
455455
null,
456456
false,
457457
false,
458-
) && null === Type::intersectUnionTypes(
459-
new Union([$candidate_atomic_type]),
460-
$conditional_type,
461-
$codebase,
462-
false,
463-
false,
464458
)) {
465459
$matching_else_types[] = $candidate_atomic_type;
466460
}

src/Psalm/Type.php

+2-20
Original file line numberDiff line numberDiff line change
@@ -803,26 +803,8 @@ public static function intersectUnionTypes(
803803

804804
//if a type is contained by the other, the intersection is the narrowest type
805805
if (!$intersection_performed) {
806-
$type_1_in_2 = UnionTypeComparator::isContainedBy(
807-
$codebase,
808-
$type_1,
809-
$type_2,
810-
false,
811-
false,
812-
null,
813-
$allow_interface_equality,
814-
$allow_float_int_equality,
815-
);
816-
$type_2_in_1 = UnionTypeComparator::isContainedBy(
817-
$codebase,
818-
$type_2,
819-
$type_1,
820-
false,
821-
false,
822-
null,
823-
$allow_interface_equality,
824-
$allow_float_int_equality,
825-
);
806+
$type_1_in_2 = UnionTypeComparator::isContainedBy($codebase, $type_1, $type_2);
807+
$type_2_in_1 = UnionTypeComparator::isContainedBy($codebase, $type_2, $type_1);
826808
if ($type_1_in_2) {
827809
$intersection_performed = true;
828810
$combined_type = $type_1->getBuilder();

tests/Template/ConditionalReturnTypeTest.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -1043,7 +1043,7 @@ function getSomething(string $string)
10431043
'code' => '<?php
10441044
/**
10451045
* @param string|int $stringOrInt
1046-
* @psalm-return ($string is non-empty-string|int ? string : int)
1046+
* @psalm-return ($stringOrInt is (non-empty-string|int) ? string : int)
10471047
*/
10481048
function getSomething($stringOrInt)
10491049
{
@@ -1053,14 +1053,15 @@ function getSomething($stringOrInt)
10531053
return "";
10541054
}
10551055
/** @var string $string */
1056-
$string;
1056+
$string = "";
10571057
$something = getSomething($string);
1058+
10581059
/** @var non-empty-string $nonEmptyString */
1059-
$nonEmptyString;
1060+
$nonEmptyString = "test";
10601061
$something2 = getSomething($nonEmptyString);
10611062
',
10621063
'assertions' => [
1063-
'$something' => 'int|string',
1064+
'$something' => 'int',
10641065
'$something2' => 'string',
10651066
],
10661067
'ignored_issues' => [],

0 commit comments

Comments
 (0)