vimeo/psalm

Psalm infers float|int when using template for positive-int|0

Open

#7.235 aberto em 28 de dez. de 2021

Ver no GitHub
 (3 comments) (0 reactions) (0 assignees)PHP (668 forks)batch import
Help wantedbuggood first issuetemplates

Métricas do repositório

Stars
 (5.369 stars)
Métricas de merge de PR
 (Mesclagem média 3d 12h) (5 fundiu PRs em 30d)

Description

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.

Guia do colaborador