forked from phpstan/phpstan-src
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbug-6822.php
More file actions
36 lines (26 loc) · 726 Bytes
/
bug-6822.php
File metadata and controls
36 lines (26 loc) · 726 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php declare(strict_types = 1);
namespace Bug6822;
use function PHPStan\Testing\assertType;
// Closures marked as @phpstan-impure should not have their return type narrowed
/** @phpstan-impure */
$closure = function (): bool {
return (bool) rand(0, 1);
};
assertType('bool', $closure());
if ($closure()) {
assertType('bool', $closure());
if ($closure()) { // should not be reported as "always true"
echo 'yes';
}
}
// Same with an explicit impure closure assigned to a variable
/** @phpstan-impure */
$impureFn = function (): int {
return rand(0, 100);
};
if ($impureFn() > 50) {
assertType('int<0, 100>', $impureFn());
if ($impureFn() > 50) { // should not be reported as "always true"
echo 'yes';
}
}