From c16d779bca1d998c5d7a27a9f94650a3aefd0907 Mon Sep 17 00:00:00 2001 From: Matt Brown Date: Sun, 25 Oct 2020 22:16:43 -0400 Subject: [PATCH] Fix #4397 - allow offsetGet on inside isset --- .../Statements/Expression/Call/MethodCallAnalyzer.php | 1 + tests/ArrayAccessTest.php | 7 +++++++ 2 files changed, 8 insertions(+) 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"; + }' + ], ]; }