From bb8ce8817da16480a5b7576568bb46336ddb6d0d Mon Sep 17 00:00:00 2001 From: Matthew Brown Date: Thu, 13 May 2021 17:31:17 -0400 Subject: [PATCH] Simplify a bit of logic in switch analysis --- .../Analyzer/Statements/Block/SwitchCaseAnalyzer.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Psalm/Internal/Analyzer/Statements/Block/SwitchCaseAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Block/SwitchCaseAnalyzer.php index 02a0416cc..e0d348583 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Block/SwitchCaseAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Block/SwitchCaseAnalyzer.php @@ -203,7 +203,11 @@ class SwitchCaseAnalyzer } } - if (($switch_condition_type = $statements_analyzer->node_data->getType($switch_condition)) + if ($switch_condition instanceof PhpParser\Node\Expr\ConstFetch + && $switch_condition->name->parts === ['true'] + ) { + $case_equality_expr = $case->cond; + } elseif (($switch_condition_type = $statements_analyzer->node_data->getType($switch_condition)) && ($case_cond_type = $statements_analyzer->node_data->getType($case->cond)) && (($switch_condition_type->isString() && $case_cond_type->isString()) || ($switch_condition_type->isInt() && $case_cond_type->isInt())