From 56369a7ba67a8214986f2a3b0eec3e666172b7fe Mon Sep 17 00:00:00 2001 From: orklah Date: Mon, 20 Dec 2021 23:10:42 +0100 Subject: [PATCH 1/3] fix wrong handling of flags in context --- .../Analyzer/Statements/Block/IfConditionalAnalyzer.php | 4 +++- .../Internal/Analyzer/Statements/Block/LoopAnalyzer.php | 6 +++++- .../Internal/Analyzer/Statements/Block/SwitchAnalyzer.php | 7 ++++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/Psalm/Internal/Analyzer/Statements/Block/IfConditionalAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Block/IfConditionalAnalyzer.php index aee9aac799a..d8caabfac6a 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Block/IfConditionalAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Block/IfConditionalAnalyzer.php @@ -163,13 +163,15 @@ function (Clause $c) use ($changed_var_ids): bool { $referenced_var_ids = $first_cond_referenced_var_ids; $if_conditional_context->referenced_var_ids = []; + $was_inside_conditional = $if_conditional_context->inside_conditional; + $if_conditional_context->inside_conditional = true; if (ExpressionAnalyzer::analyze($statements_analyzer, $cond, $if_conditional_context) === false) { throw new ScopeAnalysisException(); } - $if_conditional_context->inside_conditional = false; + $if_conditional_context->inside_conditional = $was_inside_conditional; /** @var array */ $more_cond_referenced_var_ids = $if_conditional_context->referenced_var_ids; diff --git a/src/Psalm/Internal/Analyzer/Statements/Block/LoopAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Block/LoopAnalyzer.php index 286d47b025e..1cfd4023eee 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Block/LoopAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Block/LoopAnalyzer.php @@ -622,6 +622,8 @@ private static function applyPreConditionToLoopContext( $pre_referenced_var_ids = $loop_context->referenced_var_ids; $loop_context->referenced_var_ids = []; + $was_inside_conditional = $loop_context->inside_conditional; + $loop_context->inside_conditional = true; $suppressed_issues = $statements_analyzer->getSuppressedIssues(); @@ -637,10 +639,12 @@ private static function applyPreConditionToLoopContext( } if (ExpressionAnalyzer::analyze($statements_analyzer, $pre_condition, $loop_context) === false) { + $loop_context->inside_conditional = $was_inside_conditional; + return []; } - $loop_context->inside_conditional = false; + $loop_context->inside_conditional = $was_inside_conditional; $new_referenced_var_ids = $loop_context->referenced_var_ids; $loop_context->referenced_var_ids = array_merge($pre_referenced_var_ids, $new_referenced_var_ids); diff --git a/src/Psalm/Internal/Analyzer/Statements/Block/SwitchAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Block/SwitchAnalyzer.php index b26aec7cd0f..fd492eba78d 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Block/SwitchAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Block/SwitchAnalyzer.php @@ -31,12 +31,17 @@ public static function analyze( ): void { $codebase = $statements_analyzer->getCodebase(); + $was_inside_conditional = $context->inside_conditional; + $context->inside_conditional = true; + if (ExpressionAnalyzer::analyze($statements_analyzer, $stmt->cond, $context) === false) { + $context->inside_conditional = $was_inside_conditional; + return; } - $context->inside_conditional = false; + $context->inside_conditional = $was_inside_conditional; $switch_var_id = ExpressionIdentifier::getArrayVarId( $stmt->cond, From b1a1c65714b45ea799aac4a0b23cc0fc1cd88d2b Mon Sep 17 00:00:00 2001 From: orklah Date: Mon, 20 Dec 2021 23:51:17 +0100 Subject: [PATCH 2/3] CS changes --- .../Statements/Block/IfConditionalAnalyzer.php | 4 +--- .../Analyzer/Statements/Block/SwitchCaseAnalyzer.php | 4 +--- .../Statements/Expression/AssignmentAnalyzer.php | 12 +++--------- .../Statements/Expression/Call/ArgumentsAnalyzer.php | 8 ++------ .../Expression/IncDecExpressionAnalyzer.php | 9 +++------ .../Statements/Expression/IncludeAnalyzer.php | 4 +--- src/Psalm/Internal/Codebase/Methods.php | 4 +--- 7 files changed, 12 insertions(+), 33 deletions(-) diff --git a/src/Psalm/Internal/Analyzer/Statements/Block/IfConditionalAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Block/IfConditionalAnalyzer.php index d8caabfac6a..cd4002e511d 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Block/IfConditionalAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Block/IfConditionalAnalyzer.php @@ -134,9 +134,7 @@ function (Clause $c) use ($changed_var_ids): bool { $first_cond_referenced_var_ids ); - if (!$was_inside_conditional) { - $outer_context->inside_conditional = false; - } + $outer_context->inside_conditional = $was_inside_conditional; if (!$if_context) { $if_context = clone $outer_context; diff --git a/src/Psalm/Internal/Analyzer/Statements/Block/SwitchCaseAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Block/SwitchCaseAnalyzer.php index bd97e188ec7..1afb4075013 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Block/SwitchCaseAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Block/SwitchCaseAnalyzer.php @@ -114,9 +114,7 @@ public static function analyze( return false; } - if (!$was_inside_conditional) { - $case_context->inside_conditional = false; - } + $case_context->inside_conditional = $was_inside_conditional; $statements_analyzer->node_data = clone $statements_analyzer->node_data; diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/AssignmentAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/AssignmentAnalyzer.php index 6efdf2b4d5e..a4b87cbb983 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/AssignmentAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/AssignmentAnalyzer.php @@ -551,9 +551,7 @@ public static function analyze( $context->vars_in_scope[$var_id] = Type::getNull(); - if (!$was_in_assignment) { - $context->inside_assignment = false; - } + $context->inside_assignment = $was_in_assignment; return $context->vars_in_scope[$var_id]; } @@ -571,9 +569,7 @@ public static function analyze( $context->vars_in_scope[$var_id] = Type::getEmpty(); - if (!$was_in_assignment) { - $context->inside_assignment = false; - } + $context->inside_assignment = $was_in_assignment; return $context->vars_in_scope[$var_id]; } @@ -612,9 +608,7 @@ public static function analyze( } } - if (!$was_in_assignment) { - $context->inside_assignment = false; - } + $context->inside_assignment = $was_in_assignment; return $assign_value_type; } diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentsAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentsAnalyzer.php index 4e1039ff861..0e0db090782 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentsAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentsAnalyzer.php @@ -214,9 +214,7 @@ public static function analyze( return false; } - if (!$was_inside_call) { - $context->inside_call = false; - } + $context->inside_call = $was_inside_call; if (($argument_offset === 0 && $method_id === 'array_filter' && count($args) === 2) || ($argument_offset > 0 && $method_id === 'array_map' && count($args) >= 2) @@ -1121,9 +1119,7 @@ private static function evaluateArbitraryParam( return false; } - if (!$was_inside_call) { - $context->inside_call = false; - } + $context->inside_call = $was_inside_call; } if ($arg->value instanceof PhpParser\Node\Expr\PropertyFetch diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/IncDecExpressionAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/IncDecExpressionAnalyzer.php index 53257942e32..38f9a9a3ee5 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/IncDecExpressionAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/IncDecExpressionAnalyzer.php @@ -31,15 +31,12 @@ public static function analyze( $context->inside_assignment = true; if (ExpressionAnalyzer::analyze($statements_analyzer, $stmt->var, $context) === false) { - if (!$was_inside_assignment) { - $context->inside_assignment = false; - } + $context->inside_assignment = $was_inside_assignment; + return false; } - if (!$was_inside_assignment) { - $context->inside_assignment = false; - } + $context->inside_assignment = $was_inside_assignment; $stmt_var_type = $statements_analyzer->node_data->getType($stmt->var); diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/IncludeAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/IncludeAnalyzer.php index dee8928def0..01ecaa44036 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/IncludeAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/IncludeAnalyzer.php @@ -70,9 +70,7 @@ public static function analyze( return false; } - if (!$was_inside_call) { - $context->inside_call = false; - } + $context->inside_call = $was_inside_call; $stmt_expr_type = $statements_analyzer->node_data->getType($stmt->expr); diff --git a/src/Psalm/Internal/Codebase/Methods.php b/src/Psalm/Internal/Codebase/Methods.php index 18ac4d1679b..8dadb1929ed 100644 --- a/src/Psalm/Internal/Codebase/Methods.php +++ b/src/Psalm/Internal/Codebase/Methods.php @@ -424,9 +424,7 @@ public function getMethodParams( ); } - if (!$was_inside_call) { - $context->inside_call = false; - } + $context->inside_call = $was_inside_call; } $matching_callable = InternalCallMapHandler::getMatchingCallableFromCallMapOptions( From ca25b0f8153393d158f6fbf60d04606677d109c0 Mon Sep 17 00:00:00 2001 From: orklah Date: Mon, 20 Dec 2021 23:58:49 +0100 Subject: [PATCH 3/3] always unflag before leaving a analyzer --- .../Analyzer/Statements/Block/ForeachAnalyzer.php | 2 ++ .../Analyzer/Statements/Expression/ArrayAnalyzer.php | 2 ++ .../Expression/Assignment/ArrayAssignmentAnalyzer.php | 2 ++ .../Assignment/StaticPropertyAssignmentAnalyzer.php | 2 ++ .../Analyzer/Statements/Expression/AssignmentAnalyzer.php | 8 ++++++++ .../Statements/Expression/Call/ArgumentsAnalyzer.php | 6 ++++++ .../Expression/Call/ArrayFunctionArgumentsAnalyzer.php | 2 ++ .../Statements/Expression/Call/MethodCallAnalyzer.php | 4 ++++ .../Analyzer/Statements/Expression/CastAnalyzer.php | 4 ++++ .../Statements/Expression/Fetch/ArrayFetchAnalyzer.php | 3 +++ .../Expression/Fetch/ClassConstFetchAnalyzer.php | 2 ++ .../Expression/Fetch/InstancePropertyFetchAnalyzer.php | 2 ++ .../Analyzer/Statements/Expression/IncludeAnalyzer.php | 2 ++ .../Analyzer/Statements/Expression/InstanceofAnalyzer.php | 2 ++ .../Analyzer/Statements/Expression/YieldFromAnalyzer.php | 2 ++ .../Internal/Analyzer/Statements/ExpressionAnalyzer.php | 2 ++ 16 files changed, 47 insertions(+) diff --git a/src/Psalm/Internal/Analyzer/Statements/Block/ForeachAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Block/ForeachAnalyzer.php index 515b0cd9548..8495f9d8303 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Block/ForeachAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Block/ForeachAnalyzer.php @@ -223,6 +223,8 @@ public static function analyze( $was_inside_general_use = $context->inside_general_use; $context->inside_general_use = true; if (ExpressionAnalyzer::analyze($statements_analyzer, $stmt->expr, $context) === false) { + $context->inside_general_use = $was_inside_general_use; + return false; } $context->inside_general_use = $was_inside_general_use; diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/ArrayAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/ArrayAnalyzer.php index 2e1adcfb022..7db0f813239 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/ArrayAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/ArrayAnalyzer.php @@ -311,6 +311,8 @@ private static function analyzeArrayItem( $was_inside_general_use = $context->inside_general_use; $context->inside_general_use = true; if (ExpressionAnalyzer::analyze($statements_analyzer, $item->key, $context) === false) { + $context->inside_general_use = $was_inside_general_use; + return; } $context->inside_general_use = $was_inside_general_use; diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Assignment/ArrayAssignmentAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Assignment/ArrayAssignmentAnalyzer.php index 4c4685f39c5..a2eb2c60f0a 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Assignment/ArrayAssignmentAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Assignment/ArrayAssignmentAnalyzer.php @@ -712,6 +712,8 @@ private static function analyzeNestedArrayAssignment( $child_stmt->dim, $context ) === false) { + $context->inside_general_use = $was_inside_general_use; + return; } diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Assignment/StaticPropertyAssignmentAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Assignment/StaticPropertyAssignmentAnalyzer.php index b50cea62b7f..ebe454a968a 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Assignment/StaticPropertyAssignmentAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Assignment/StaticPropertyAssignmentAnalyzer.php @@ -82,6 +82,8 @@ public static function analyze( $context->inside_general_use = true; if (ExpressionAnalyzer::analyze($statements_analyzer, $prop_name, $context) === false) { + $context->inside_general_use = $was_inside_general_use; + return false; } diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/AssignmentAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/AssignmentAnalyzer.php index a4b87cbb983..f39bf696d80 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/AssignmentAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/AssignmentAnalyzer.php @@ -236,6 +236,8 @@ public static function analyze( } if (ExpressionAnalyzer::analyze($statements_analyzer, $assign_value, $context) === false) { + $context->inside_general_use = $was_inside_general_use; + if ($var_id) { if ($array_var_id) { $context->removeDescendents($array_var_id, null, $assign_value_type); @@ -1501,10 +1503,14 @@ private static function analyzePropertyAssignment( // this can happen when the user actually means to type $this->, but there's // a variable on the next line if (ExpressionAnalyzer::analyze($statements_analyzer, $assign_var->var, $context) === false) { + $context->inside_general_use = $was_inside_general_use; + return; } if (ExpressionAnalyzer::analyze($statements_analyzer, $assign_var->name, $context) === false) { + $context->inside_general_use = $was_inside_general_use; + return; } @@ -1693,6 +1699,8 @@ private static function analyzeAssignmentToVariable( $context->inside_general_use = true; if (ExpressionAnalyzer::analyze($statements_analyzer, $assign_var->name, $context) === false) { + $context->inside_general_use = $was_inside_general_use; + return; } diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentsAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentsAnalyzer.php index 0e0db090782..9dd368ea64f 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentsAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentsAnalyzer.php @@ -211,6 +211,8 @@ public static function analyze( $context->inside_call = true; if (ExpressionAnalyzer::analyze($statements_analyzer, $arg->value, $context) === false) { + $context->inside_call = $was_inside_call; + return false; } @@ -1116,6 +1118,8 @@ private static function evaluateArbitraryParam( $context->inside_call = true; if (ExpressionAnalyzer::analyze($statements_analyzer, $arg->value, $context) === false) { + $context->inside_call = $was_inside_call; + return false; } @@ -1225,6 +1229,8 @@ private static function handleByRefFunctionArg( $arg->value, $context ) === false) { + $context->inside_assignment = $was_inside_assignment; + return false; } diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArrayFunctionArgumentsAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArrayFunctionArgumentsAnalyzer.php index 167dfd5196b..654e9bd829b 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArrayFunctionArgumentsAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArrayFunctionArgumentsAnalyzer.php @@ -163,6 +163,8 @@ function ($arg) { $args[$i]->value, $context ) === false) { + $context->inside_assignment = $was_inside_assignment; + return false; } diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/MethodCallAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/MethodCallAnalyzer.php index 8619d29132c..eef4a321e24 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/MethodCallAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/MethodCallAnalyzer.php @@ -61,6 +61,8 @@ public static function analyze( if ($existing_stmt_var_type) { $statements_analyzer->node_data->setType($stmt->var, $existing_stmt_var_type); } elseif (ExpressionAnalyzer::analyze($statements_analyzer, $stmt->var, $context) === false) { + $context->inside_call = $was_inside_call; + return false; } @@ -70,6 +72,8 @@ public static function analyze( $context->inside_call = true; if (ExpressionAnalyzer::analyze($statements_analyzer, $stmt->name, $context) === false) { + $context->inside_call = $was_inside_call; + return false; } } diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/CastAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/CastAnalyzer.php index 78ccb7756f5..4f80b23e0a7 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/CastAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/CastAnalyzer.php @@ -186,6 +186,8 @@ public static function analyze( $was_inside_general_use = $context->inside_general_use; $context->inside_general_use = true; if (ExpressionAnalyzer::analyze($statements_analyzer, $stmt->expr, $context) === false) { + $context->inside_general_use = $was_inside_general_use; + return false; } $context->inside_general_use = $was_inside_general_use; @@ -208,6 +210,8 @@ public static function analyze( $was_inside_general_use = $context->inside_general_use; $context->inside_general_use = true; if (ExpressionAnalyzer::analyze($statements_analyzer, $stmt->expr, $context) === false) { + $context->inside_general_use = $was_inside_general_use; + return false; } $context->inside_general_use = $was_inside_general_use; diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/ArrayFetchAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/ArrayFetchAnalyzer.php index 9d98b118e74..7a7d167a84c 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/ArrayFetchAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/ArrayFetchAnalyzer.php @@ -119,6 +119,9 @@ public static function analyze( $context->inside_unset = false; if (ExpressionAnalyzer::analyze($statements_analyzer, $stmt->dim, $context) === false) { + $context->inside_unset = $was_inside_unset; + $context->inside_general_use = $was_inside_general_use; + return false; } diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/ClassConstFetchAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/ClassConstFetchAnalyzer.php index ce007570863..7fb934dccfe 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/ClassConstFetchAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/ClassConstFetchAnalyzer.php @@ -380,6 +380,8 @@ public static function analyze( $context->inside_general_use = true; if (ExpressionAnalyzer::analyze($statements_analyzer, $stmt->class, $context) === false) { + $context->inside_general_use = $was_inside_general_use; + return false; } diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/InstancePropertyFetchAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/InstancePropertyFetchAnalyzer.php index c4fc3eda05d..35fb44b1acd 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/InstancePropertyFetchAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/InstancePropertyFetchAnalyzer.php @@ -51,6 +51,8 @@ public static function analyze( } if (ExpressionAnalyzer::analyze($statements_analyzer, $stmt->var, $context) === false) { + $context->inside_general_use = $was_inside_general_use; + return false; } diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/IncludeAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/IncludeAnalyzer.php index 01ecaa44036..9fd4f163ef1 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/IncludeAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/IncludeAnalyzer.php @@ -67,6 +67,8 @@ public static function analyze( $context->inside_call = true; if (ExpressionAnalyzer::analyze($statements_analyzer, $stmt->expr, $context) === false) { + $context->inside_call = $was_inside_call; + return false; } diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/InstanceofAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/InstanceofAnalyzer.php index 673c44d09f5..e87bfe2fa8e 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/InstanceofAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/InstanceofAnalyzer.php @@ -25,6 +25,8 @@ public static function analyze( $context->inside_general_use = true; if (ExpressionAnalyzer::analyze($statements_analyzer, $stmt->expr, $context) === false) { + $context->inside_general_use = $was_inside_general_use; + return false; } diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/YieldFromAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/YieldFromAnalyzer.php index fa89c13451e..f9c03c41335 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/YieldFromAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/YieldFromAnalyzer.php @@ -47,6 +47,8 @@ public static function analyze( $always_non_empty_array ) === false ) { + $context->inside_call = $was_inside_call; + return false; } diff --git a/src/Psalm/Internal/Analyzer/Statements/ExpressionAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/ExpressionAnalyzer.php index 9e80e394c6a..0ce2af836e8 100644 --- a/src/Psalm/Internal/Analyzer/Statements/ExpressionAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/ExpressionAnalyzer.php @@ -453,6 +453,8 @@ private static function handleExpression( $was_inside_call = $context->inside_call; $context->inside_call = true; if (PrintAnalyzer::analyze($statements_analyzer, $stmt, $context) === false) { + $context->inside_call = $was_inside_call; + return false; } $context->inside_call = $was_inside_call;