From 5eb7e4df6ddb22fad2bfd14da255700152a948fe Mon Sep 17 00:00:00 2001 From: tuqqu Date: Tue, 3 Oct 2023 02:53:51 +0200 Subject: [PATCH] Allow isset check for interface properties --- .../Expression/Fetch/AtomicPropertyFetchAnalyzer.php | 9 ++++++--- tests/InterfaceTest.php | 8 ++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/AtomicPropertyFetchAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/AtomicPropertyFetchAnalyzer.php index d6289b6687b..9275876612c 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/AtomicPropertyFetchAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/AtomicPropertyFetchAnalyzer.php @@ -192,6 +192,7 @@ public static function analyze( $statements_analyzer, $codebase, $stmt, + $context, $lhs_type_part, $intersection_types, $class_exists, @@ -1127,6 +1128,7 @@ private static function handleNonExistentClass( StatementsAnalyzer $statements_analyzer, Codebase $codebase, PhpParser\Node\Expr\PropertyFetch $stmt, + Context $context, TNamedObject $lhs_type_part, array $intersection_types, bool &$class_exists, @@ -1150,10 +1152,11 @@ private static function handleNonExistentClass( } } - if (!$class_exists && + if (!$class_exists //interfaces can't have properties. Except when they do... In PHP Core, they can - !in_array($fq_class_name, ['UnitEnum', 'BackedEnum'], true) && - !in_array('UnitEnum', $codebase->getParentInterfaces($fq_class_name)) + && !in_array($fq_class_name, ['UnitEnum', 'BackedEnum'], true) + && !in_array('UnitEnum', $codebase->getParentInterfaces($fq_class_name)) + && !$context->inside_isset ) { if (IssueBuffer::accepts( new NoInterfaceProperties( diff --git a/tests/InterfaceTest.php b/tests/InterfaceTest.php index 91d56c16a64..0a21ebd5894 100644 --- a/tests/InterfaceTest.php +++ b/tests/InterfaceTest.php @@ -736,6 +736,14 @@ function takesAorB(SomeClass|SomeInterface $some): void { 'ignored_issues' => [], 'php_version' => '8.0', ], + 'interfacePropertyIssetCheck' => [ + 'code' => 'x); + }', + ], ]; }