From ac8d48941356c902eeadf15c6dc480e1c79d211c Mon Sep 17 00:00:00 2001 From: klimick Date: Wed, 3 May 2023 22:22:33 +0300 Subject: [PATCH] Fix ParadoxicalCondition with complex match expression --- .../Statements/Expression/MatchAnalyzer.php | 7 ++++--- tests/MatchTest.php | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/MatchAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/MatchAnalyzer.php index c0b614ae487..b05c21fd8be 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/MatchAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/MatchAnalyzer.php @@ -110,10 +110,11 @@ public static function analyze( $stmt->cond->getAttributes(), ); } - } elseif ($stmt->cond instanceof PhpParser\Node\Expr\FuncCall - || $stmt->cond instanceof PhpParser\Node\Expr\MethodCall - || $stmt->cond instanceof PhpParser\Node\Expr\StaticCall + } elseif ($stmt->cond instanceof PhpParser\Node\Expr\ConstFetch + && $stmt->cond->name->toString() === 'true' ) { + // do nothing + } else { $switch_var_id = '$__tmp_switch__' . (int) $stmt->cond->getAttribute('startFilePos'); $condition_type = $statements_analyzer->node_data->getType($stmt->cond) ?? Type::getMixed(); diff --git a/tests/MatchTest.php b/tests/MatchTest.php index 8350f7b9632..1b2cba32b59 100644 --- a/tests/MatchTest.php +++ b/tests/MatchTest.php @@ -95,6 +95,20 @@ function test(array $array): array 'ignored_issues' => [], 'php_version' => '8.1', ], + 'multipleIdenticalChecksInOneArm' => [ + 'code' => ' "1 or 2 or 3", + "type4", "type5", "type6" => "4 or 5 or 6", + default => "rest", + }; + }', + 'assertions' => [], + 'ignored_issues' => [], + 'php_version' => '8.1', + ], 'multipleInstanceOfConditionsInOneArm' => [ 'code' => '