Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix type inference of closure params #7135

Merged
merged 2 commits into from Dec 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -181,8 +181,6 @@ public static function analyze(

if (($arg->value instanceof PhpParser\Node\Expr\Closure
|| $arg->value instanceof PhpParser\Node\Expr\ArrowFunction)
&& $template_result
&& $template_result->lower_bounds
&& $param
&& !$arg->value->getDocComment()
) {
Expand All @@ -191,7 +189,7 @@ public static function analyze(
$args,
$method_id,
$context,
$template_result,
$template_result ?? new TemplateResult([], []),
$argument_offset,
$arg,
$param
Expand Down
22 changes: 22 additions & 0 deletions tests/CallableTest.php
Expand Up @@ -63,6 +63,28 @@ function(string $a) {
'error_levels' => [],
'7.4',
],
'inferArgFromClassContext' => [
'<?php
final class Calc
{
/**
* @param Closure(int, int): int $_fn
*/
public function __invoke(Closure $_fn): int
{
return $_fn(42, 42);
}
}
$calc = new Calc();
$a = $calc(fn($a, $b) => $a + $b);',
'assertions' => [
'$a' => 'int',
],
'error_levels' => [],
'7.4',
],
'varReturnType' => [
'<?php
$add_one = function(int $a) : int {
Expand Down
2 changes: 0 additions & 2 deletions tests/FunctionCallTest.php
Expand Up @@ -1377,8 +1377,6 @@ function (array $matches) : string {
'<?php
/**
* @param string[] $ids
* @psalm-suppress MissingClosureReturnType
* @psalm-suppress MixedArgumentTypeCoercion
*/
function(array $ids): array {
return \preg_replace_callback(
Expand Down