mirror of
https://github.com/danog/psalm.git
synced 2025-01-22 05:41:20 +01:00
Merge pull request #6589 from orklah/strict-callable
Better understanding of Templates in lhs of callable TKeyedArray
This commit is contained in:
commit
96ed2526e8
@ -9,6 +9,7 @@ use Psalm\Type;
|
||||
use Psalm\Type\Atomic;
|
||||
use Psalm\Type\Atomic\TArray;
|
||||
use Psalm\Type\Atomic\TCallable;
|
||||
use Psalm\Type\Atomic\TClassString;
|
||||
use Psalm\Type\Atomic\TClosure;
|
||||
use Psalm\Type\Atomic\TKeyedArray;
|
||||
use Psalm\Type\Atomic\TList;
|
||||
@ -430,6 +431,24 @@ class CallableTypeComparator
|
||||
strtolower($lhs_atomic_type->value) . '::',
|
||||
$calling_method_id ?: $file_name
|
||||
);
|
||||
} elseif ($lhs_atomic_type instanceof Atomic\TTemplateParam) {
|
||||
$lhs_template_type = $lhs_atomic_type->as;
|
||||
if ($lhs_template_type->isSingle()) {
|
||||
$lhs_template_atomic_type = $lhs_template_type->getSingleAtomic();
|
||||
$member_id = null;
|
||||
if ($lhs_template_atomic_type instanceof TNamedObject) {
|
||||
$member_id = $lhs_template_atomic_type->value;
|
||||
} elseif ($lhs_template_atomic_type instanceof TClassString) {
|
||||
$member_id = $lhs_template_atomic_type->as;
|
||||
}
|
||||
|
||||
if ($member_id) {
|
||||
$codebase->analyzer->addMixedMemberName(
|
||||
strtolower($member_id) . '::',
|
||||
$calling_method_id ?: $file_name
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -450,6 +469,16 @@ class CallableTypeComparator
|
||||
foreach ($lhs->getAtomicTypes() as $lhs_atomic_type) {
|
||||
if ($lhs_atomic_type instanceof TNamedObject) {
|
||||
$class_name = $lhs_atomic_type->value;
|
||||
} elseif ($lhs_atomic_type instanceof Atomic\TTemplateParam) {
|
||||
$lhs_template_type = $lhs_atomic_type->as;
|
||||
if ($lhs_template_type->isSingle()) {
|
||||
$lhs_template_atomic_type = $lhs_template_type->getSingleAtomic();
|
||||
if ($lhs_template_atomic_type instanceof TNamedObject) {
|
||||
$class_name = $lhs_template_atomic_type->value;
|
||||
} elseif ($lhs_template_atomic_type instanceof TClassString) {
|
||||
$class_name = $lhs_template_atomic_type->as;
|
||||
}
|
||||
}
|
||||
} elseif ($lhs_atomic_type instanceof Type\Atomic\TClassString
|
||||
&& $lhs_atomic_type->as
|
||||
) {
|
||||
|
@ -1680,4 +1680,9 @@ class Union implements TypeNode
|
||||
{
|
||||
return count($this->literal_float_types) > 0;
|
||||
}
|
||||
|
||||
public function getSingleAtomic(): Atomic
|
||||
{
|
||||
return reset($this->types);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user