Skip to content
Permalink
Browse files

Add support for arrow function inference

  • Loading branch information
muglug committed Nov 27, 2019
1 parent a154191 commit 113bf921f61b64278025e76e221bdf883bdd6421
Showing with 15 additions and 4 deletions.
  1. +2 −1 src/Psalm/Internal/Analyzer/Statements/Expression/CallAnalyzer.php
  2. +13 −3 tests/FunctionCallTest.php
@@ -435,7 +435,8 @@ protected static function checkFunctionArguments(
$codebase = $statements_analyzer->getCodebase();
if ($arg->value instanceof PhpParser\Node\Expr\Closure
if (($arg->value instanceof PhpParser\Node\Expr\Closure
|| $arg->value instanceof PhpParser\Node\Expr\ArrowFunction)
&& $template_result
&& $template_result->generic_params
&& $param
@@ -844,7 +844,7 @@ function foo(): array {
'<?php
/** @param list<int> $list */
function takesList(array $list): void {}
takesList(
array_map(
"intval",
@@ -872,7 +872,7 @@ function foo(): array {
'<?php
/** @param list<string> $list */
function takesList(array $list): void {}
takesList(
array_map(
function (string $str): string { return $str . "x"; },
@@ -887,7 +887,7 @@ function (string $str): string { return $str . "x"; },
* @var array<string, int> $array
*/
$a = array_map($callable, $array);
/**
* @var callable $callable
* @var array<string, int> $array
@@ -1925,6 +1925,16 @@ function ($dateTime) {
);
}',
],
'inferArrayMapArrowFunctionReturnType' => [
'<?php
/** @return array<string> */
function Foo(DateTime ...$dateTimes) : array {
return array_map(
fn ($dateTime) => (string) ($dateTime->format("c")),
$dateTimes
);
}',
],
'noImplicitAssignmentToStringFromMixedWithDocblockTypes' => [
'<?php
/** @param string $s */

0 comments on commit 113bf92

Please sign in to comment.
You can’t perform that action at this time.