diff --git a/src/Psalm/Internal/Type/SimpleAssertionReconciler.php b/src/Psalm/Internal/Type/SimpleAssertionReconciler.php index edbd18973..3cb551454 100644 --- a/src/Psalm/Internal/Type/SimpleAssertionReconciler.php +++ b/src/Psalm/Internal/Type/SimpleAssertionReconciler.php @@ -2000,7 +2000,7 @@ class SimpleAssertionReconciler extends Reconciler $did_remove_type = false; foreach ($existing_var_atomic_types as $type) { - if ($type instanceof TArray || $type instanceof TKeyedArray || $type instanceof TList) { + if ($type instanceof TArray || $type instanceof TKeyedArray) { $array_types[] = $type; } elseif ($type instanceof TCallable) { $array_types[] = new TCallableKeyedArray([ @@ -2094,11 +2094,11 @@ class SimpleAssertionReconciler extends Reconciler $did_remove_type = false; foreach ($existing_var_atomic_types as $type) { - if ($type instanceof TList - || ($type instanceof TKeyedArray && $type->is_list) - ) { - if ($is_non_empty && $type instanceof TList && !$type instanceof TNonEmptyList) { - $array_types[] = Type::getNonEmptyListAtomic($type->type_param); + if ($type instanceof TKeyedArray && $type->is_list) { + if ($is_non_empty && !$type->isNonEmpty()) { + $properties = $type->properties; + $properties[0] = $properties[0]->setPossiblyUndefined(false); + $array_types[] = $type->setProperties($properties); $did_remove_type = true; } else { $array_types[] = $type; diff --git a/src/Psalm/Type/Atomic/TKeyedArray.php b/src/Psalm/Type/Atomic/TKeyedArray.php index ae25473c6..fe6556699 100644 --- a/src/Psalm/Type/Atomic/TKeyedArray.php +++ b/src/Psalm/Type/Atomic/TKeyedArray.php @@ -358,6 +358,9 @@ class TKeyedArray extends Atomic public function isNonEmpty(): bool { + if ($this->is_list) { + return !$this->properties[0]->possibly_undefined; + } foreach ($this->properties as $property) { if (!$property->possibly_undefined) { return true;