Skip to content

Commit 187cb9b

Browse files
committed
Cover nested float zeros and a repeated 0.0 in the redundant assignment test
A zero two arrays deep pins the recursion of containsFloatZero(), and `$x = 0.0; $x = 0.0;` pins that a repeated zero is no longer reported: the type cannot tell a literal 0.0 from a narrowed zero of unknown sign.
1 parent 929b66f commit 187cb9b

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

‎tests/PHPStan/Rules/DeadCode/data/unused-variable-redundant-signed-zero.php‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,28 @@ function nonZeroFloatIsStillRedundant(): void
5858
$x = 1.5;
5959
sink($x);
6060
}
61+
62+
function zeroInNestedArray(): void
63+
{
64+
$a = [[-0.0]];
65+
sink($a);
66+
$a = [[0.0]];
67+
sink($a);
68+
}
69+
70+
function zeroAtNestedOffset(): void
71+
{
72+
$a = ['x' => ['y' => -0.0]];
73+
sink($a);
74+
$a['x']['y'] = 0.0;
75+
sink($a);
76+
}
77+
78+
function repeatedPositiveZeroIsNotReportedEither(): void
79+
{
80+
// the type of $x cannot tell this 0.0 from a narrowed zero of unknown sign
81+
$x = 0.0;
82+
sink($x);
83+
$x = 0.0;
84+
sink($x);
85+
}

0 commit comments

Comments
 (0)