Skip to content

Commit

Permalink
Allow destructuring of callable array
Browse files Browse the repository at this point in the history
Fixes #2653
  • Loading branch information
muglug committed Jan 17, 2020
1 parent 471d761 commit 2c48d42
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Psalm/Type/Union.php
Expand Up @@ -625,7 +625,7 @@ public function hasType($type_string)
*/
public function hasArray()
{
return isset($this->types['array']);
return isset($this->types['array']) || isset($this->types['callable-array']);
}

/**
Expand Down
18 changes: 18 additions & 0 deletions tests/CallableTest.php
Expand Up @@ -713,6 +713,24 @@ function c(callable $c) : void {
}
}'
],
'destructureCallableArray' => [
'<?php
function getCallable(): callable {
return [DateTimeImmutable::class, "createFromFormat"];
}
$callable = getCallable();
if (!is_array($callable)) {
exit;
}
[$classOrObject, $method] = $callable;',
[
'$classOrObject' => 'class-string|object',
'$method' => 'string'
]
],
];
}

Expand Down

0 comments on commit 2c48d42

Please sign in to comment.