mirror of
https://github.com/danog/psalm.git
synced 2025-01-22 05:41:20 +01:00
Limited fix for #5028
This commit is contained in:
parent
e3d73a3166
commit
3be1bb7342
@ -177,7 +177,7 @@ class InstancePropertyFetchAnalyzer
|
|||||||
|
|
||||||
if ($stmt_var_type->isNullable() && !$stmt_var_type->ignore_nullable_issues) {
|
if ($stmt_var_type->isNullable() && !$stmt_var_type->ignore_nullable_issues) {
|
||||||
// we can only be sure that the variable is possibly null if we know the var_id
|
// we can only be sure that the variable is possibly null if we know the var_id
|
||||||
if (!$context->inside_isset && $var_id) {
|
if (!$context->inside_isset && $stmt->name instanceof PhpParser\Node\Identifier) {
|
||||||
if (IssueBuffer::accepts(
|
if (IssueBuffer::accepts(
|
||||||
new PossiblyNullPropertyFetch(
|
new PossiblyNullPropertyFetch(
|
||||||
'Cannot get property on possibly null variable ' . $stmt_var_id . ' of type ' . $stmt_var_type,
|
'Cannot get property on possibly null variable ' . $stmt_var_id . ' of type ' . $stmt_var_type,
|
||||||
|
@ -2380,6 +2380,18 @@ class PropertyTypeTest extends TestCase
|
|||||||
[],
|
[],
|
||||||
'8.0'
|
'8.0'
|
||||||
],
|
],
|
||||||
|
'possiblyNullOnFunctionCallCoalesced' => [
|
||||||
|
'<?php
|
||||||
|
class Foo
|
||||||
|
{
|
||||||
|
/** @var int */
|
||||||
|
public $a = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
function accessOnVar(?Foo $bar, string $b) : void {
|
||||||
|
echo $bar->{$b} ?? null;
|
||||||
|
}',
|
||||||
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3511,6 +3523,21 @@ class PropertyTypeTest extends TestCase
|
|||||||
}',
|
}',
|
||||||
'error_message' => 'MismatchingDocblockPropertyType',
|
'error_message' => 'MismatchingDocblockPropertyType',
|
||||||
],
|
],
|
||||||
|
'possiblyNullOnFunctionCallNotCoalesced' => [
|
||||||
|
'<?php
|
||||||
|
function getC() : ?C {
|
||||||
|
return rand(0, 1) ? new C() : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function foo() : void {
|
||||||
|
echo getC()->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
class C {
|
||||||
|
public int $id = 1;
|
||||||
|
}',
|
||||||
|
'error_message' => 'PossiblyNullPropertyFetch',
|
||||||
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user