New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PossiblyNullReference not detected using callable classes #5809
Labels
Comments
I found these snippets: https://psalm.dev/r/165262da3d<?php
declare(strict_types=1);
class Location {
private int $id;
public function __construct(int $id) {
$this->id = $id;
}
public function getId(): int
{
return $this->id;
}
}
/**
* @psalm-immutable
*/
class Application
{
private ?Location $location;
public function __construct(?Location $location = null ) {
$this->location = $location;
}
public function getLocation(): ?Location
{
return $this->location;
}
}
class TakesId
{
public function __invoke(
int $location
): int {
return $location;
}
}
$takesId = new TakesId();
$application = new Application();
($takesId)($application->getLocation()->getId());
https://psalm.dev/r/9a3e913407<?php
declare(strict_types=1);
class Location {
private int $id;
public function __construct(int $id) {
$this->id = $id;
}
public function getId(): int
{
return $this->id;
}
}
/**
* @psalm-immutable
*/
class Application
{
private ?Location $location;
public function __construct(?Location $location = null ) {
$this->location = $location;
}
public function getLocation(): ?Location
{
return $this->location;
}
}
class TakesId
{
public function __invoke(
int $location
): int {
return $location;
}
}
$takesId = new TakesId();
$application = new Application();
$takesId->__invoke($application->getLocation()->getId());
|
Simplified: https://psalm.dev/r/024ec41453 |
I found these snippets: https://psalm.dev/r/024ec41453<?php
interface Location {
public function getId(): int;
}
/** @psalm-immutable */
interface Application {
public function getLocation(): ?Location;
}
interface TakesId {
public function __invoke(int $location): int;
}
function f(TakesId $takesId, Application $application): void {
($takesId)($application->getLocation()->getId());
}
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See the last line here, which should warn
PossiblyNullReference
:https://psalm.dev/r/165262da3d
changing the method call to
__invoke
correctly surfaces the error:https://psalm.dev/r/9a3e913407
The text was updated successfully, but these errors were encountered: