-
Hi! I am attempting to narrow down a function's I've attempted to define a template https://psalm.dev/r/3bf0a368da <?php
/**
* @template MIN of int
* @template MAX of int
*
* @psalm-param MIN $min
* @psalm-param MAX $max
*
* @psalm-return list<int<MIN, MAX>>
*/
function my_range(int $min, int $max): array {
$result = [];
for ($i = $min; $i <= $max; $i++) $result[] = $i;
return $result;
}
var_dump(my_range(1, 6)); // I want the return type to be list<int<1, 6>> based on the constant boundaries given. Is there a way to achieve this? Discussion #7901 appears to be similar to what I am searching for. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
There's no support for that for now. There are still major flaws in int range handling that would probably need to be prioritized before we can add template support inside integer ranges. If you're looking for a one time solution, it should be possible to create a plugin that would make this work for this particular function |
Beta Was this translation helpful? Give feedback.
There's no support for that for now. There are still major flaws in int range handling that would probably need to be prioritized before we can add template support inside integer ranges.
If you're looking for a one time solution, it should be possible to create a plugin that would make this work for this particular function