mirror of
https://github.com/danog/psalm.git
synced 2025-01-21 21:31:13 +01:00
Track variable usage in bool to int casts (#5349)
Fixes vimeo/psalm#4956
This commit is contained in:
parent
185827a7ab
commit
8be77aaa2e
@ -71,10 +71,18 @@ class CastAnalyzer
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2316,6 +2316,18 @@ class UnusedVariableTest extends TestCase
|
||||
};
|
||||
}
|
||||
',
|
||||
],
|
||||
'usedInIntCastInAssignment' => [
|
||||
'<?php
|
||||
/** @return mixed */
|
||||
function f() {
|
||||
$a = random_int(0, 10) >= 5 ? true : false;
|
||||
|
||||
$b = (int) $a;
|
||||
|
||||
return $b;
|
||||
}
|
||||
'
|
||||
]
|
||||
];
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user