Skip to content

Commit 2464761

Browse files
phpstan-botclaude
andcommitted
Add tests for multiple callable parameter acceptors purity check
Tests the code path where a variable holds a union of closures (multiple callable parameter acceptors): one test with mixed pure/impure closures verifying no narrowing, and one with all pure closures verifying narrowing still works. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent dbdc192 commit 2464761

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

tests/PHPStan/Analyser/nsrt/bug-12686.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,43 @@
2121
if ($h()) {
2222
assertType('true', $h());
2323
}
24+
25+
// Multiple callable parameter acceptors (union of closures)
26+
// When one variant is impure, the combined result should be impure
27+
/** @phpstan-impure */
28+
$impure = function (): bool {
29+
return (bool) rand(0, 1);
30+
};
31+
32+
$pure = function (): bool {
33+
return true;
34+
};
35+
36+
if (rand(0, 1)) {
37+
$g = $impure;
38+
} else {
39+
$g = $pure;
40+
}
41+
42+
if ($g()) {
43+
assertType('bool', $g());
44+
}
45+
46+
// Multiple callable parameter acceptors where all are pure
47+
$pure1 = function (): bool {
48+
return true;
49+
};
50+
51+
$pure2 = function (): bool {
52+
return true;
53+
};
54+
55+
if (rand(0, 1)) {
56+
$p = $pure1;
57+
} else {
58+
$p = $pure2;
59+
}
60+
61+
if ($p()) {
62+
assertType('true', $p());
63+
}

0 commit comments

Comments
 (0)