1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 20:34:47 +01:00

fix refining lowercase string and non-empty-string together

This commit is contained in:
orklah 2022-04-05 21:05:23 +02:00
parent 83c534414e
commit b72f0564bc
2 changed files with 27 additions and 0 deletions

View File

@ -45,8 +45,11 @@ use Psalm\Type\Atomic\TList;
use Psalm\Type\Atomic\TLiteralFloat;
use Psalm\Type\Atomic\TLiteralInt;
use Psalm\Type\Atomic\TLiteralString;
use Psalm\Type\Atomic\TLowercaseString;
use Psalm\Type\Atomic\TMixed;
use Psalm\Type\Atomic\TNamedObject;
use Psalm\Type\Atomic\TNonEmptyLowercaseString;
use Psalm\Type\Atomic\TNonEmptyString;
use Psalm\Type\Atomic\TNull;
use Psalm\Type\Atomic\TNumeric;
use Psalm\Type\Atomic\TObject;
@ -793,6 +796,13 @@ class AssertionReconciler extends Reconciler
$matching_atomic_type = $new_range;
}
// Lowercase-string and non-empty-string are compatible but none is contained into the other completely
if (($type_2_atomic instanceof TLowercaseString && $type_1_atomic instanceof TNonEmptyString) ||
($type_2_atomic instanceof TNonEmptyString && $type_1_atomic instanceof TLowercaseString)
) {
$matching_atomic_type = new TNonEmptyLowercaseString();
}
if (!$atomic_comparison_results->type_coerced && $atomic_comparison_results->scalar_type_match_found) {
$any_scalar_type_match_found = true;
}

View File

@ -2038,6 +2038,23 @@ class AssertAnnotationTest extends TestCase
}
',
],
'assertNonEmptyStringWithLowercaseString' => [
'code' => '<?php
/** @psalm-assert non-empty-string $input */
function assertLowerCase(string $input): void { throw new \Exception($input . " irrelevant"); }
/**
* @param lowercase-string $input
* @return non-empty-lowercase-string
*/
function makeLowerNonEmpty(string $input): string
{
assertLowerCase($input);
return $input;
}',
],
];
}