psalm icon indicating copy to clipboard operation
psalm copied to clipboard

Allow to set custom error message for `@psalm-if-this-is`

Open klimick opened this issue 2 years ago • 1 comments

https://psalm.dev/r/ad37d58f21

Consider to example above. Error message: Class type must be ArrayList<(B:fn-arraylist::filternulls as mixed)|null> current type ArrayList<int> But it can be more understandable: Redundant call. ArrayList does not contain null values. It would be nice have possibility to set custom error message for @psalm-if-this-is.

klimick avatar Jul 17 '22 12:07 klimick

I found these snippets:

https://psalm.dev/r/ad37d58f21
<?php

/**
 * @template A
 */
final class ArrayList
{
    /**
     * @template B
     * @psalm-if-this-is ArrayList<B|null>
     *
     * @return ArrayList<B>
     */
    public function filterNulls(): ArrayList
    {
        die('???');
    }
}

/** @var ArrayList<int> */
$list = new ArrayList();
$_noNulls = $list->filterNulls();
Psalm output (using commit 8c716f8):

ERROR: IfThisIsMismatch - 22:20 - Class type must be ArrayList<(B:fn-arraylist::filternulls as mixed)|null> current type ArrayList<int>

psalm-github-bot[bot] avatar Jul 17 '22 12:07 psalm-github-bot[bot]