-
Notifications
You must be signed in to change notification settings - Fork 574
Expand file tree
/
Copy pathbug-14249.php
More file actions
84 lines (64 loc) · 1.38 KB
/
bug-14249.php
File metadata and controls
84 lines (64 loc) · 1.38 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php // lint >= 8.1
declare(strict_types = 1);
namespace Bug14249;
use function PHPStan\Testing\assertType;
/**
* @phpstan-assert-if-true positive-int $value
*/
function is_positive_int(mixed $value): bool {
return is_int($value) && $value > 0;
}
function f(mixed $v): void {
$f1 = is_positive_int(...);
$f2 = 'Bug14249\is_positive_int';
if (is_positive_int($v)) {
assertType('int<1, max>', $v);
}
if ($f1($v)) {
assertType('int<1, max>', $v);
}
if ($f2($v)) {
assertType('int<1, max>', $v);
}
}
/**
* @template T of bool
* @param T $if
* @phpstan-assert (T is true ? true : false) $condition
*/
function assertIfTemplated(mixed $condition, bool $if)
{
}
function doTemplated(): void {
$f1 = assertIfTemplated(...);
$f2 = 'Bug14249\assertIfTemplated';
$v = getMixed();
assertIfTemplated($v, true);
assertType('true', $v);
$v = getMixed();
$f1($v, true);
assertType('true', $v);
$v = getMixed();
$f2($v, true);
assertType('true', $v);
$v = getMixed();
assertIfTemplated($v, false);
assertType('false', $v);
$v = getMixed();
$f1($v, false);
assertType('false', $v);
$v = getMixed();
$f2($v, false);
assertType('false', $v);
}
/** @phpstan-impure */
function getMixed(): mixed {}
function maybeCallable() {
$f2 = 'Bug14249\assertIfTemplated';
if (rand(0,1)) {
$f2 = 'notCallable';
}
$v = getMixed();
$f2($v, false);
assertType('mixed', $v);
}