|
| 1 | +<?php // lint >= 8.0 |
| 2 | + |
| 3 | +declare(strict_types = 1); |
| 4 | + |
| 5 | +namespace Bug13247; |
| 6 | + |
| 7 | +use Traversable; |
| 8 | + |
| 9 | +/** |
| 10 | + * @template K as array-key |
| 11 | + * @template V |
| 12 | + * |
| 13 | + * @param array<K, V>|Traversable<K, V> $input |
| 14 | + * |
| 15 | + * @return array<K, V> |
| 16 | + */ |
| 17 | +function as_array(array|Traversable $input): array { |
| 18 | + return iter_as_array($input); |
| 19 | +} |
| 20 | + |
| 21 | +/** |
| 22 | + * @template K as array-key |
| 23 | + * @template V |
| 24 | + * |
| 25 | + * @param iterable<K, V> $input |
| 26 | + * |
| 27 | + * @return array<K, V> |
| 28 | + */ |
| 29 | +function iter_as_array(iterable $input): array { |
| 30 | + return as_array($input); |
| 31 | +} |
| 32 | + |
| 33 | +/** |
| 34 | + * @param array|Traversable $input |
| 35 | + * |
| 36 | + * @return array |
| 37 | + */ |
| 38 | +function as_array2(array|Traversable $input): array { |
| 39 | + return iter_as_array2($input); |
| 40 | +} |
| 41 | + |
| 42 | +/** |
| 43 | + * @param iterable $input |
| 44 | + * |
| 45 | + * @return array |
| 46 | + */ |
| 47 | +function iter_as_array2(iterable $input): array { |
| 48 | + return as_array2($input); |
| 49 | +} |
| 50 | + |
| 51 | +/** |
| 52 | + * @param array<int, int>|Traversable<int, int> $input |
| 53 | + * |
| 54 | + * @return array<int, int> |
| 55 | + */ |
| 56 | +function as_array3(array|Traversable $input): array { |
| 57 | + return iter_as_array3($input); |
| 58 | +} |
| 59 | + |
| 60 | +/** |
| 61 | + * @param iterable<int, int> $input |
| 62 | + * |
| 63 | + * @return array<int, int> |
| 64 | + */ |
| 65 | +function iter_as_array3(iterable $input): array { |
| 66 | + return as_array3($input); |
| 67 | +} |
| 68 | + |
| 69 | +/** |
| 70 | + * @phpstan-template T of iterable<int, int> |
| 71 | + * |
| 72 | + * @param T $input |
| 73 | + * |
| 74 | + * @return mixed |
| 75 | + */ |
| 76 | +function test1(iterable $input) { |
| 77 | + test2($input); |
| 78 | + iter_as_array($input); |
| 79 | + |
| 80 | + return as_array($input); |
| 81 | +} |
| 82 | + |
| 83 | +/** |
| 84 | + * @phpstan-template U of Traversable<int, int>|array<int, int> |
| 85 | + * |
| 86 | + * @param U $input |
| 87 | + * |
| 88 | + * @return mixed |
| 89 | + */ |
| 90 | +function test2($input) { |
| 91 | + test1($input); |
| 92 | + iter_as_array($input); |
| 93 | + |
| 94 | + return as_array($input); |
| 95 | +} |
0 commit comments