diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/CastAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/CastAnalyzer.php index fb7ec2b2f25..453e939eec0 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/CastAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/CastAnalyzer.php @@ -71,10 +71,18 @@ public static function analyze( if (count($maybe) === 1 && current($maybe) instanceof Type\Atomic\TBool) { $as_int = false; - $statements_analyzer->node_data->setType($stmt, new Type\Union([ + $type = new Type\Union([ new Type\Atomic\TLiteralInt(0), new Type\Atomic\TLiteralInt(1), - ])); + ]); + + if ($statements_analyzer->data_flow_graph + && $statements_analyzer->data_flow_graph instanceof \Psalm\Internal\Codebase\VariableUseGraph + ) { + $type->parent_nodes = $maybe_type->parent_nodes; + } + + $statements_analyzer->node_data->setType($stmt, $type); } } diff --git a/tests/UnusedVariableTest.php b/tests/UnusedVariableTest.php index 524db9d906f..2c88118af94 100644 --- a/tests/UnusedVariableTest.php +++ b/tests/UnusedVariableTest.php @@ -2316,6 +2316,18 @@ function createFailingFunction(RuntimeException $exception): Closure }; } ', + ], + 'usedInIntCastInAssignment' => [ + '= 5 ? true : false; + + $b = (int) $a; + + return $b; + } + ' ] ]; }