1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-27 04:45:20 +01:00

Prioritize TCallableString handling to avoid simpler checks for TLowercaseString vs TString (#5811)

This commit is contained in:
orklah 2021-05-21 13:44:26 +02:00 committed by GitHub
parent 4b17cc9a4b
commit 4d6be66d98
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 9 deletions

View File

@ -13,6 +13,7 @@ use Psalm\Type\Atomic\TClassString;
use Psalm\Type\Atomic\TCallableString;
use Psalm\Type\Atomic\TFalse;
use Psalm\Type\Atomic\TFloat;
use Psalm\Type\Atomic\TLowercaseString;
use Psalm\Type\Atomic\TTemplateParam;
use Psalm\Type\Atomic\TTemplateParamClass;
use Psalm\Type\Atomic\TDependentGetClass;
@ -70,6 +71,16 @@ class ScalarTypeComparator
return true;
}
if ($input_type_part instanceof TCallableString
&& (get_class($container_type_part) === TString::class
|| get_class($container_type_part) === TSingleLetter::class
|| get_class($container_type_part) === TNonEmptyString::class
|| get_class($container_type_part) === TNonFalsyString::class
|| get_class($container_type_part) === TLowercaseString::class)
) {
return true;
}
if (($container_type_part instanceof Type\Atomic\TLowercaseString
|| $container_type_part instanceof Type\Atomic\TNonEmptyLowercaseString)
&& $input_type_part instanceof TString
@ -417,15 +428,6 @@ class ScalarTypeComparator
return true;
}
if ($input_type_part instanceof TCallableString
&& (get_class($container_type_part) === TString::class
|| get_class($container_type_part) === TSingleLetter::class
|| get_class($container_type_part) === TNonEmptyString::class
|| get_class($container_type_part) === TNonFalsyString::class)
) {
return true;
}
if ($input_type_part instanceof TNumericString
&& get_class($container_type_part) === TNonEmptyString::class
) {

View File

@ -116,6 +116,10 @@ class TypeComparatorTest extends TestCase
'array{foo?: string}&array<string, mixed>',
'array<empty, empty>',
],
'Lowercase-stringAndCallable-string' => [
'lowercase-string',
'callable-string',
],
];
}
}