mirror of
https://github.com/danog/psalm.git
synced 2025-01-22 05:41:20 +01:00
Merge pull request #9018 from orklah/TClosure
create proper TClosure instead of TNamedObject with a Closure value
This commit is contained in:
commit
435acb823c
@ -1246,7 +1246,7 @@ class AssertionFinder
|
||||
$instanceof_class = $codebase->classlikes->getUnAliasedName($instanceof_class);
|
||||
}
|
||||
|
||||
return [new IsType(new TNamedObject($instanceof_class))];
|
||||
return [new IsType(TNamedObject::createFromName($instanceof_class))];
|
||||
}
|
||||
|
||||
if ($this_class_name
|
||||
|
@ -384,6 +384,9 @@ abstract class Atomic implements TypeNode
|
||||
|
||||
case 'non-empty-mixed':
|
||||
return new TNonEmptyMixed();
|
||||
|
||||
case 'Closure':
|
||||
return new TClosure('Closure');
|
||||
}
|
||||
|
||||
if (strpos($value, '-') && strpos($value, 'OCI-') !== 0) {
|
||||
|
@ -255,4 +255,21 @@ class TNamedObject extends Atomic
|
||||
{
|
||||
return ['extra_types'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, TNamedObject|TTemplateParam|TIterable|TObjectWithProperties> $extra_types
|
||||
*/
|
||||
public static function createFromName(
|
||||
string $value,
|
||||
bool $is_static = false,
|
||||
bool $definite_class = false,
|
||||
array $extra_types = [],
|
||||
bool $from_docblock = false
|
||||
): TNamedObject {
|
||||
if ($value === 'Closure') {
|
||||
return new TClosure($value, null, null, null, [], $extra_types, $from_docblock);
|
||||
}
|
||||
|
||||
return new TNamedObject($value, $is_static, $definite_class, $extra_types, $from_docblock);
|
||||
}
|
||||
}
|
||||
|
@ -914,6 +914,26 @@ class ClosureTest extends TestCase
|
||||
/** @psalm-suppress UndefinedFunction */
|
||||
unknown(...);',
|
||||
],
|
||||
'reconcileClosure' => [
|
||||
'code' => '<?php
|
||||
/**
|
||||
* @param Closure|callable-string $callable
|
||||
*/
|
||||
function use_callable($callable) : void
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Closure|string $var
|
||||
*/
|
||||
function test($var) : void
|
||||
{
|
||||
if (is_callable($var))
|
||||
use_callable($var);
|
||||
else
|
||||
echo $var; // $var should be string, instead it\'s considered to be Closure|string.
|
||||
}',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user