vimeo/psalm
Auf GitHub ansehenPsalm infers float|int when using template for positive-int|0
Open
#7.235 geöffnet am 28. Dez. 2021
Help wantedbuggood first issuetemplates
Repository-Metriken
- Stars
- (5.369 Stars)
- PR-Merge-Metriken
- (Durchschn. Merge 3T 12h) (5 gemergte PRs in 30 T)
Beschreibung
Given the following snippet https://psalm.dev/r/28b89bee3b
<?php
/**
* @psalm-pure
* @psalm-template T as positive-int|0
* @psalm-param T $depth
*/
function recursiveFn(int $depth = 1): void {
if ($depth > 1) {
recursiveFn($depth - 1);
}
}
Psalm reports:
ERROR: ArgumentTypeCoercion - 10:21 - Argument 1 of recursiveFn expects 0|positive-int, parent type float|int provided
Given the exactly the same snippet, except not using the template https://psalm.dev/r/412e21cd88
<?php
/**
* @psalm-pure
* @psalm-param positive-int|0 $depth
*/
function recursiveFn(int $depth = 1): void {
if ($depth > 1) {
recursiveFn($depth - 1);
}
}
There are no (related) errors; presumably $depth is correctly identified as positive-int|0 here.