psalm
psalm copied to clipboard
Allow to set custom error message for `@psalm-if-this-is`
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
.
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>