psalm --alter introduce syntax errors into code
psalm --alter adds non existent classes nulld, nulle, \Closured into source code
> tools/psalm.phar --version
Psalm 4.x-dev@
> php -v
PHP 8.0.18 (cli) (built: Apr 13 2022 02:45:05) ( NTS gcc x86_64 )
tools/psalm.phar --alter --issues=MissingParamType --dry-run
static function map(
iterable $arr,
- int|string|array|\Closure $map = null,
- mixed $where = null,
- mixed $skip = null,
- mixed $while = null,
+ int|nulle $map = null,
+ int|nulld $where = null,
+ int|nulld $skip = null,
+ int|nulld $while = null,
mixed $reverse = false,
*
* @param iterable<mixed> $arr
*/
- static function _while(iterable $arr, mixed $while): \Generator {
+ static function _while(iterable $arr, \Closured $while): \Generator {
Hey @parf, can you reproduce the issue on https://psalm.dev ?
--alter --issues=MissingParamType --dry-run
not really, there is no --alter optoin. here is a link to sample code https://psalm.dev/r/59942a73d8
this code however does not have above error
I found these snippets:
https://psalm.dev/r/59942a73d8
<?php
abstract class Arr0 {
/**
* @param iterable<mixed> $arr
* @param \Closure|int|string|string[] $map
*
* @return mixed[]
*/
static function map(
iterable $arr,
int|string|array|\Closure $map = null,
mixed $where = null,
mixed $skip = null,
mixed $while = null,
mixed $reverse = false,
): array {
return [];
}
}
Psalm output (using commit f960d71):
No issues!
Could you check if you have weird characters in your file? Maybe accents or wrongly encoded unicode chars?
I have the same issue. It changes the paramType to what it deems correct concatenated with the last letter of the original typing. For example mixed will change to intd instead of int.
@orklah it's a genuine bug I've been able to reproduce.
https://psalm.dev/r/4cbc908e6e (press Fix code).
I found these snippets:
https://psalm.dev/r/4cbc908e6e
<?php
abstract class Arr0 {
/**
* @param iterable<mixed> $arr
* @param \Closure|int|string|string[] $map
* @psalm-suppress UnusedParam
*/
static function map(
iterable $arr,
int|string|array|\Closure $map = null,
mixed $where = null,
mixed $skip = null,
mixed $while = null,
mixed $reverse = false,
): void {
}
}
$a = Arr0::map([], 1, 1, 1, 1);
Psalm output (using commit 12f33fa):
ERROR: AssignmentToVoid - 21:1 - Cannot assign $a to type void
INFO: UnusedVariable - 21:1 - $a is never referenced or the value is not used
But I don't think we should be fixing explicit mixed in parameter types at all.
This is fixed in #9803, isn't it?