-
Notifications
You must be signed in to change notification settings - Fork 471
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Infer parameter types in arrow functions
- Loading branch information
1 parent
d4ded32
commit 8fdc2d3
Showing
4 changed files
with
139 additions
and
37 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php // lint >= 7.4 | ||
|
||
namespace ArrowFunctionTypes; | ||
|
||
use function PHPStan\Testing\assertType; | ||
|
||
class Foo | ||
{ | ||
|
||
/** @var array<int, array{foo: string, bar: int}> */ | ||
private $arrayShapes; | ||
|
||
public function doFoo(): void | ||
{ | ||
array_map(fn(array $a): array => assertType('array(\'foo\' => string, \'bar\' => int)', $a), $this->arrayShapes); | ||
$a = array_map(fn(array $a) => $a, $this->arrayShapes); | ||
assertType('array<int, array(\'foo\' => string, \'bar\' => int)>', $a); | ||
|
||
array_map(fn($b) => assertType('array(\'foo\' => string, \'bar\' => int)', $b), $this->arrayShapes); | ||
$b = array_map(fn($b) => $b['foo'], $this->arrayShapes); | ||
assertType('array<int, string>', $b); | ||
} | ||
|
||
public function doBar(): void | ||
{ | ||
usort($this->arrayShapes, fn(array $a, array $b): int => assertType('array(\'foo\' => string, \'bar\' => int)', $a)); | ||
} | ||
|
||
public function doBar2(): void | ||
{ | ||
usort($this->arrayShapes, fn (array $a, array $b): int => assertType('array(\'foo\' => string, \'bar\' => int)', $b)); | ||
} | ||
|
||
public function doBaz(): void | ||
{ | ||
usort($this->arrayShapes, fn ($a, $b): int => assertType('array(\'foo\' => string, \'bar\' => int)', $a)); | ||
} | ||
|
||
public function doBaz2(): void | ||
{ | ||
usort($this->arrayShapes, fn ($a, $b): int => assertType('array(\'foo\' => string, \'bar\' => int)', $b)); | ||
} | ||
|
||
} |