Skip to content

Commit e856423

Browse files
authored
Merge pull request #11354 from orklah/11062
push original callable when creating callable-object in order to keep return type
2 parents c1f27c9 + d3f1ca8 commit e856423

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/Psalm/Internal/Type/SimpleNegatedAssertionReconciler.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1698,7 +1698,7 @@ private static function reconcileArray(
16981698
}
16991699
} elseif ($type instanceof TCallable) {
17001700
$non_array_types[] = new TCallableString();
1701-
$non_array_types[] = new TCallableObject();
1701+
$non_array_types[] = new TCallableObject($type->from_docblock, $type);
17021702
$redundant = false;
17031703
} elseif ($type instanceof TIterable) {
17041704
if (!$type->type_params[0]->isMixed() || !$type->type_params[1]->isMixed()) {

tests/CallableTest.php

+15
Original file line numberDiff line numberDiff line change
@@ -2384,6 +2384,21 @@ function f(callable $c): void {
23842384
f($ca);
23852385
PHP,
23862386
],
2387+
'callableWithoutArray' => [
2388+
'code' => '<?php
2389+
/**
2390+
* @param array|(callable():array) $var
2391+
*/
2392+
function text($var): array
2393+
{
2394+
if (is_array($var)) {
2395+
return $var;
2396+
}
2397+
2398+
//callable-string can\'t specify return type but it doesn\'t error
2399+
return call_user_func($var);
2400+
}',
2401+
],
23872402
];
23882403
}
23892404

0 commit comments

Comments
 (0)