Skip to content

Commit 02066c7

Browse files
committed
Fix ClosureType::equals() for pure/impure closures
1 parent fa27078 commit 02066c7

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

src/Type/ClosureType.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,8 @@ public function equals(Type $type): bool
236236
return false;
237237
}
238238

239-
return $this->describe(VerbosityLevel::precise()) === $type->describe(VerbosityLevel::precise());
239+
return $this->describe(VerbosityLevel::precise()) === $type->describe(VerbosityLevel::precise())
240+
&& $this->isPure()->equals($type->isPure());
240241
}
241242

242243
public function describe(VerbosityLevel $level): string

tests/PHPStan/Rules/DeadCode/NoopRuleTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,4 +153,9 @@ public function testBug11361(): void
153153
$this->analyse([__DIR__ . '/data/bug-11361.php'], []);
154154
}
155155

156+
public function testBug13067(): void
157+
{
158+
$this->analyse([__DIR__ . '/data/bug-13067.php'], []);
159+
}
160+
156161
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace Bug13067;
4+
5+
function process(bool $real): void
6+
{
7+
$printSum = function(float $sum): void {};
8+
9+
if ($real) {
10+
$printSum = function(float $sum): void {
11+
echo $sum . "\n";
12+
};
13+
}
14+
15+
$sum = 3;
16+
$printSum($sum);
17+
}
18+
19+
/**
20+
* @param pure-callable $pureCallable
21+
*/
22+
function process2(bool $real, callable $pureCallable, callable $callable): void
23+
{
24+
$cb = $pureCallable;
25+
if ($real) {
26+
$cb = $callable;
27+
}
28+
29+
$cb();
30+
}

0 commit comments

Comments
 (0)