-
Notifications
You must be signed in to change notification settings - Fork 660
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
Incorrect RedundantCondition with null safe property access and null coalesce #10316
Comments
I found these snippets: https://psalm.dev/r/14b17f9fa4<?php
interface A {
public function a(): string;
public function copy(): self;
}
class B {
public function __construct(public A|null $a = null) {}
public function something(): string
{
$value = $this->a?->copy()->a() ?? '';
return $value;
}
public function trace(): string
{
/** @psalm-trace $value */
$value = $this->a?->copy()->a();
return $value;
}
}
|
Maybe this is related (seen in Symfony): |
I found these snippets: https://psalm.dev/r/46409b9f5a<?php
declare(strict_types = 1);
class Request {}
interface TokenInterface {}
class AuthenticationException {
public function getPrevious(): ?\AuthenticationException
{
return null;
}
public function getToken(): ?\TokenInterface
{
return null;
}
}
class Response {
public function __construct(?AuthenticationException $e) {}
}
interface AuthenticationEntryPointInterface
{
public function start(Request $request, AuthenticationException $authException = null): Response;
}
readonly class AuthenticationEntryPoint implements AuthenticationEntryPointInterface
{
public function start(Request $request, AuthenticationException $authException = null): Response
{
if (
($prev = $authException?->getPrevious())
&& $authException?->getToken()
) {
return new Response($prev);
}
return new Response(null);
}
}
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When accessing properties/methods with the null safe operator, the result seems to be evaluated incorrectly.
The resulting type should be
<Type>|null
, but psalm evaluates only<Type>
.https://psalm.dev/r/14b17f9fa4
The text was updated successfully, but these errors were encountered: