diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/MethodCallAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/MethodCallAnalyzer.php index 80b8976d3..3c48a6368 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/MethodCallAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/MethodCallAnalyzer.php @@ -138,6 +138,7 @@ class MethodCallAnalyzer extends \Psalm\Internal\Analyzer\Statements\Expression\ && $stmt->name instanceof PhpParser\Node\Identifier && $class_type->isNullable() && !$class_type->ignore_nullable_issues + && !($stmt->name->name === 'offsetGet' && $context->inside_isset) ) { if (IssueBuffer::accepts( new PossiblyNullReference( diff --git a/tests/ArrayAccessTest.php b/tests/ArrayAccessTest.php index 25d38015b..fec6d60de 100644 --- a/tests/ArrayAccessTest.php +++ b/tests/ArrayAccessTest.php @@ -976,6 +976,13 @@ class ArrayAccessTest extends TestCase test(["a", "b"]); test(new ArrayObject(["a", "b"]));' ], + 'nullCoalesceArrayAccess' => [ + ' $a */ + function foo(?ArrayAccess $a) : void { + echo $a[0] ?? "default"; + }' + ], ]; }