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' => '