From 245b944c85e5db7b47994fec180bf4de39ea1f4a Mon Sep 17 00:00:00 2001 From: Matt Brown Date: Sun, 17 Jan 2021 11:59:59 -0500 Subject: [PATCH] Fix #5028 - avoid false-positive on dynamic property fetch after ternary --- .../Expression/Fetch/InstancePropertyFetchAnalyzer.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/InstancePropertyFetchAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/InstancePropertyFetchAnalyzer.php index b5768fcac..cadcbe7bd 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/InstancePropertyFetchAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/InstancePropertyFetchAnalyzer.php @@ -176,7 +176,8 @@ class InstancePropertyFetchAnalyzer } if ($stmt_var_type->isNullable() && !$stmt_var_type->ignore_nullable_issues) { - if (!$context->inside_isset) { + // we can only be sure that the variable is possibly null if we know the var_id + if (!$context->inside_isset && $var_id) { if (IssueBuffer::accepts( new PossiblyNullPropertyFetch( 'Cannot get property on possibly null variable ' . $stmt_var_id . ' of type ' . $stmt_var_type,