-
Notifications
You must be signed in to change notification settings - Fork 472
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Assertions done on a variable used in a closure should be transferred…
… inside the closure
- Loading branch information
1 parent
77157d7
commit 36dac3d
Showing
3 changed files
with
65 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
tests/PHPStan/Analyser/data/specified-types-closure-use.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace SpecifiedTypesClosureUse; | ||
|
||
use PhpParser\Node\Expr\MethodCall; | ||
use PhpParser\Node\Identifier; | ||
use function PHPStan\Analyser\assertType; | ||
|
||
class Foo | ||
{ | ||
|
||
public function doFoo(MethodCall $call, MethodCall $bar): void | ||
{ | ||
if ($call->name instanceof Identifier && $bar->name instanceof Identifier) { | ||
function () use ($call): void { | ||
assertType('PhpParser\Node\Identifier', $call->name); | ||
assertType('mixed', $bar->name); | ||
}; | ||
|
||
assertType('PhpParser\Node\Identifier', $call->name); | ||
} | ||
} | ||
|
||
public function doBar(MethodCall $call, MethodCall $bar): void | ||
{ | ||
if ($call->name instanceof Identifier && $bar->name instanceof Identifier) { | ||
$a = 1; | ||
function () use ($call, &$a): void { | ||
assertType('PhpParser\Node\Identifier', $call->name); | ||
assertType('mixed', $bar->name); | ||
}; | ||
|
||
assertType('PhpParser\Node\Identifier', $call->name); | ||
} | ||
} | ||
|
||
} |