Skip to content

Commit faf2535

Browse files
array_map should return non-empty array when a non-empty array is given (#815)
1 parent a973da3 commit faf2535

File tree

4 files changed

+25
-1
lines changed

4 files changed

+25
-1
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
/**
4+
* @param non-empty-array<string, string> $arr
5+
* @return non-empty-array<string, int>
6+
*/
7+
function takesNonEmptyArray(array $arr): array
8+
{
9+
return array_map(strlen(...), $arr);
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
/**
4+
* @param non-empty-list<string> $list
5+
* @return non-empty-list<int>
6+
*/
7+
function takesNonEmptyList(array $list): array
8+
{
9+
return array_map(strlen(...), $list);
10+
}

crates/analyzer/tests/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ macro_rules! test_case {
3434
test_case!(accessing_undefined_class_constant);
3535
test_case!(argument_count);
3636
test_case!(array_list_reconciliation);
37+
test_case!(array_map_non_empty_array);
38+
test_case!(array_map_non_empty_list);
3739
test_case!(array_shape_fields);
3840
test_case!(array_unique_non_empty);
3941
test_case!(assert_concrete_to_template_type);

crates/prelude/assets/extensions/standard.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4711,7 +4711,9 @@ function array_filter(array $array, null|callable $callback = null, int $mode =
47114711
* @param array<K, V> $array
47124712
* @param array<S> ...$arrays
47134713
*
4714-
* @return ($array is list<V> ? list<U> : array<K, U>)
4714+
* @return ($array is list<V>
4715+
* ? ($array is non-empty-list<V> ? non-empty-list<U> : list<U>)
4716+
* : ($array is non-empty-array<K, V> ? non-empty-array<K, U> : array<K, U>))
47154717
*/
47164718
function array_map(null|callable $callback, array $array, array ...$arrays): array
47174719
{

0 commit comments

Comments
 (0)