psalm
psalm copied to clipboard
False positive PossiblyNullArgument
https://psalm.dev/r/6b57f1fc40
I'm assuming that what's going on here is that psalm can't deduce that $y never changes before the execution of the closure. However because we know that $y is immutable (or readonly), we know that the null check should narrow the type that's captured by the closure.
I found these snippets:
https://psalm.dev/r/6b57f1fc40
<?php
class X {
/** @psalm-readonly */
private ?int $y;
public function __construct() {
$this->y = 1;
}
function test() : void {
$arr = [1, 2, 3];
if ($this->y !== null)
array_map(fn($z) => $this->y + $z, $arr);
}
}
Psalm output (using commit 3600d51):
INFO: PossiblyNullOperand - 13:30 - Left operand cannot be nullable, got int|null