Skip to content

Commit c728ffa

Browse files
committed
Update
1 parent 5597583 commit c728ffa

19 files changed

+29
-31
lines changed

src/Psalm/Internal/Analyzer/Statements/Block/ForeachAnalyzer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ public static function checkIteratorType(
457457
}
458458

459459
// if it's an empty array, we cannot iterate over it
460-
if ($iterator_atomic_type instanceof TArray && $iterator_atomic_type->isEmptyArray()) {
460+
if ($iterator_atomic_type instanceof TArray && $iterator_atomic_type->isEmpty()) {
461461
$always_non_empty_array = false;
462462
$has_valid_iterator = true;
463463
continue;

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
use Psalm\Storage\FunctionLikeStorage;
4242
use Psalm\Storage\MethodStorage;
4343
use Psalm\Type;
44+
use Psalm\Type\Atomic\ArrayInterface;
4445
use Psalm\Type\Atomic\TArray;
4546
use Psalm\Type\Atomic\TCallable;
4647
use Psalm\Type\Atomic\TCallableKeyedArray;
@@ -1236,7 +1237,7 @@ private static function evaluateArbitraryParam(
12361237

12371238
$t = $context->vars_in_scope[$var_id]->getBuilder();
12381239
foreach ($t->getAtomicTypes() as $k => $type) {
1239-
if ($type instanceof TArray && $type->isEmptyArray()) {
1240+
if ($type instanceof ArrayInterface && $type->isEmpty()) {
12401241
$t->removeType($k);
12411242
$t->addType(
12421243
new TArray(

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ public static function handleAddition(
279279
array_unshift($properties, $arg_value_type);
280280

281281
$by_ref_type = new Union([$objectlike_list->setProperties($properties)]);
282-
} elseif ($array_type instanceof TArray && $array_type->isEmptyArray()) {
282+
} elseif ($array_type instanceof TArray && $array_type->isEmpty()) {
283283
$by_ref_type = new Union([new TKeyedArray([
284284
$arg_value_type,
285285
], null, null, true)]);

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use Psalm\Plugin\EventHandler\Event\AfterFunctionCallAnalysisEvent;
2626
use Psalm\Storage\FunctionLikeStorage;
2727
use Psalm\Type;
28+
use Psalm\Type\Atomic\ArrayInterface;
2829
use Psalm\Type\Atomic\TArray;
2930
use Psalm\Type\Atomic\TCallable;
3031
use Psalm\Type\Atomic\TCallableKeyedArray;
@@ -383,8 +384,8 @@ private static function getReturnTypeFromCallMapWithArgs(
383384
return Type::getIntRange($min, $max);
384385
}
385386

386-
if ($atomic_types['array'] instanceof TArray
387-
&& $atomic_types['array']->isEmptyArray()
387+
if ($atomic_types['array'] instanceof ArrayInterface
388+
&& $atomic_types['array']->isEmpty()
388389
) {
389390
return Type::getInt(false, 0);
390391
}

src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/ArrayFetchAnalyzer.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -1120,7 +1120,7 @@ private static function handleArrayAccessOnArray(
11201120

11211121
if ($in_assignment) {
11221122
if ($type instanceof TArray) {
1123-
$from_empty_array = $type->isEmptyArray();
1123+
$from_empty_array = $type->isEmpty();
11241124

11251125
if (count($key_values) === 1) {
11261126
$single_atomic = $key_values[0];
@@ -1249,15 +1249,15 @@ private static function handleArrayAccessOnTArray(
12491249
): void {
12501250
// if we're assigning to an empty array with a key offset, refashion that array
12511251
if ($in_assignment) {
1252-
if ($type->isEmptyArray()) {
1252+
if ($type->isEmpty()) {
12531253
$type = $type->setTypeParams([
12541254
$offset_type->isMixed()
12551255
? Type::getArrayKey()
12561256
: $offset_type->freeze(),
12571257
$type->type_params[1],
12581258
]);
12591259
}
1260-
} elseif (!$type->isEmptyArray()) {
1260+
} elseif (!$type->isEmpty()) {
12611261
$expected_offset_type = $type->type_params[0]->hasMixed()
12621262
? new Union([new TArrayKey])
12631263
: $type->type_params[0];

src/Psalm/Internal/Analyzer/Statements/Expression/SimpleTypeInferer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,7 @@ private static function handleUnpackedArray(
823823
);
824824
}
825825
} elseif ($unpacked_atomic_type instanceof TArray) {
826-
if ($unpacked_atomic_type->isEmptyArray()) {
826+
if ($unpacked_atomic_type->isEmpty()) {
827827
continue;
828828
}
829829
$array_creation_info->can_create_objectlike = false;

src/Psalm/Internal/Codebase/ConstantTypeResolver.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ public static function resolve(
210210
$visited_constant_ids + [$c_id => true],
211211
);
212212

213-
if ($spread_array instanceof TArray && $spread_array->isEmptyArray()) {
213+
if ($spread_array instanceof TArray && $spread_array->isEmpty()) {
214214
continue;
215215
}
216216

src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayColumnReturnTypeProvider.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public static function getFunctionReturnType(FunctionReturnTypeProviderEvent $ev
108108
continue;
109109
}
110110
if (!$row_shape instanceof TKeyedArray) {
111-
if ($row_shape instanceof TArray && $row_shape->isEmptyArray()) {
111+
if ($row_shape instanceof TArray && $row_shape->isEmpty()) {
112112
continue;
113113
}
114114
$ok = false;

src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayFillKeysReturnTypeProvider.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public static function getFunctionReturnType(FunctionReturnTypeProviderEvent $ev
4747
) {
4848
$results = [];
4949
foreach ($first_arg_type->getArrays() as $array) {
50-
if ($array instanceof TArray && $array->isEmptyArray()) {
50+
if ($array instanceof TArray && $array->isEmpty()) {
5151
$results []= $array;
5252
continue;
5353
} elseif ($array instanceof TKeyedArray && !$array->fallback_params) {

src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayMapReturnTypeProvider.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public static function getFunctionReturnType(FunctionReturnTypeProviderEvent $ev
9898
} elseif ($call_arg_type
9999
&& $call_arg_type->isSingle()
100100
&& ($call_arg_atomic = $call_arg_type->getSingleAtomic()) instanceof TArray
101-
&& $call_arg_atomic->isEmptyArray()
101+
&& $call_arg_atomic->isEmpty()
102102
) {
103103
$array_arg_types []= [];
104104
$orig_types []= $call_arg_type;

src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayMergeReturnTypeProvider.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ public static function getFunctionReturnType(FunctionReturnTypeProviderEvent $ev
202202
}
203203

204204
if ($unpacked_type_part instanceof TArray) {
205-
if ($unpacked_type_part->isEmptyArray()) {
205+
if ($unpacked_type_part->isEmpty()) {
206206
continue;
207207
}
208208

src/Psalm/Internal/Type/SimpleAssertionReconciler.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ private static function reconcileNonEmptyCountable(
637637
|| ($assertion instanceof HasAtLeastCount
638638
&& $array_atomic_type->min_count < $assertion->count)
639639
) {
640-
if ($array_atomic_type->isEmptyArray()) {
640+
if ($array_atomic_type->isEmpty()) {
641641
$existing_var_type->removeType($k);
642642
} else {
643643
$non_empty_array = new TNonEmptyArray(
@@ -2399,7 +2399,7 @@ private static function reconcileList(
23992399
}
24002400
}
24012401

2402-
if ($type->isEmptyArray()) {
2402+
if ($type->isEmpty()) {
24032403
//we allow an empty array to pass as a list. We keep the type as empty array though (more precise)
24042404
$array_types[] = $type;
24052405
}

src/Psalm/Internal/Type/SimpleNegatedAssertionReconciler.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use Psalm\Storage\Assertion\NotInArray;
2525
use Psalm\Storage\Assertion\NotNonEmptyCountable;
2626
use Psalm\Type;
27+
use Psalm\Type\Atomic\ArrayInterface;
2728
use Psalm\Type\Atomic\Scalar;
2829
use Psalm\Type\Atomic\TArray;
2930
use Psalm\Type\Atomic\TArrayKey;
@@ -630,7 +631,7 @@ private static function reconcileNotNonEmptyCountable(
630631
));
631632
}
632633
}
633-
} elseif (!$array_atomic_type instanceof TArray || !$array_atomic_type->isEmptyArray()) {
634+
} elseif (!$array_atomic_type instanceof ArrayInterface || !$array_atomic_type->isEmpty()) {
634635
$redundant = false;
635636

636637
if (!$count) {

src/Psalm/Internal/Type/TypeCombiner.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ private static function scrapeTypeProperties(
588588
$combination->array_always_filled = false;
589589
}
590590

591-
if (!$type->isEmptyArray()) {
591+
if (!$type->isEmpty()) {
592592
$combination->all_arrays_lists = false;
593593
$combination->all_arrays_class_string_maps = false;
594594
}

src/Psalm/Internal/TypeVisitor/ContainsLiteralVisitor.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Psalm\Internal\TypeVisitor;
66

7+
use Psalm\Type\Atomic\ArrayInterface;
78
use Psalm\Type\Atomic\TArray;
89
use Psalm\Type\Atomic\TFalse;
910
use Psalm\Type\Atomic\TLiteralFloat;
@@ -32,7 +33,7 @@ protected function enterNode(TypeNode $type): ?int
3233
return self::STOP_TRAVERSAL;
3334
}
3435

35-
if ($type instanceof TArray && $type->isEmptyArray()) {
36+
if ($type instanceof ArrayInterface && $type->isEmpty()) {
3637
$this->contains_literal = true;
3738
return self::STOP_TRAVERSAL;
3839
}

src/Psalm/Type/Atomic.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Psalm\Internal\TypeVisitor\ClasslikeReplacer;
1616
use Psalm\Storage\UnserializeMemoryUsageSuppressionTrait;
1717
use Psalm\Type;
18+
use Psalm\Type\Atomic\ArrayInterface;
1819
use Psalm\Type\Atomic\TArray;
1920
use Psalm\Type\Atomic\TArrayKey;
2021
use Psalm\Type\Atomic\TBool;
@@ -908,7 +909,7 @@ public function isFalsy(): bool
908909
return true;
909910
}
910911

911-
if ($this instanceof TArray && $this->isEmptyArray()) {
912+
if ($this instanceof ArrayInterface && $this->isEmpty()) {
912913
return true;
913914
}
914915

src/Psalm/Type/Atomic/TArray.php

+2-7
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ public function getMaxCount(): ?int
6363
}
6464
public function getCount(): ?int
6565
{
66-
return $this->isEmptyArray() ? 0 : null;
66+
return $this->isEmpty() ? 0 : null;
6767
}
6868
public function isEmpty(): bool
6969
{
70-
return $this->isEmptyArray();
70+
return $this->type_params[1]->isNever();
7171
}
7272
public function isNonEmpty(): bool
7373
{
@@ -134,11 +134,6 @@ public function getAssertionString(): string
134134
return $this->getId();
135135
}
136136

137-
public function isEmptyArray(): bool
138-
{
139-
return $this->type_params[1]->isNever();
140-
}
141-
142137
/**
143138
* @return static
144139
*/

src/Psalm/Type/Reconciler.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1153,7 +1153,7 @@ private static function adjustTKeyedArrayType(
11531153
foreach ($existing_types[$base_key]->getAtomicTypes() as $base_atomic_type) {
11541154
if ($base_atomic_type instanceof TKeyedArray
11551155
|| ($base_atomic_type instanceof TArray
1156-
&& !$base_atomic_type->isEmptyArray())
1156+
&& !$base_atomic_type->isEmpty())
11571157
|| $base_atomic_type instanceof TClassStringMap
11581158
) {
11591159
$new_base_type = $existing_types[$base_key];

src/Psalm/Type/UnionTrait.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,6 @@ public function areArraysAllNonEmpty(): bool
483483

484484
public function areArraysAllEmpty(): bool
485485
{
486-
$result = true;
487486
foreach ($this->types as $t) {
488487
if ($t instanceof ArrayInterface
489488
&& !$t->isEmpty()
@@ -1670,8 +1669,7 @@ public function getSingleAtomic(): Atomic
16701669
*/
16711670
public function isEmptyArray(): bool
16721671
{
1673-
return count($this->types) === 1
1674-
&& isset($this->types['array<never, never>']);
1672+
return $this->isArray() && $this->areArraysAllEmpty();
16751673
}
16761674

16771675
/**

0 commit comments

Comments
 (0)