1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-22 05:41:20 +01:00

Merge pull request #6729 from orklah/lowercase-string_and_non-empty-string

strlen of strtolower of string is not always true
This commit is contained in:
orklah 2021-10-24 19:21:42 +02:00 committed by GitHub
commit db8f7180dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 1 deletions

View File

@ -216,7 +216,8 @@ class ConcatAnalyzer
$lowercase_type
);
$non_empty_string = Type::getNonEmptyString();
$non_empty_string = clone $numeric_type;
$non_empty_string->addType(new Type\Atomic\TNonEmptyString());
$has_non_empty = UnionTypeComparator::isContainedBy(
$codebase,

View File

@ -585,6 +585,11 @@ class ScalarTypeComparator
return true;
}
if ($input_type_part instanceof TLowercaseString
&& get_class($container_type_part) === TNonEmptyString::class) {
return false;
}
if ($input_type_part->getKey() === $container_type_part->getKey()) {
return true;
}

View File

@ -841,6 +841,24 @@ class ConditionalReturnTypeTest extends TestCase
}
'
],
'strlenReturnsIntForLowercaseString' => [
'<?php
/**
* @psalm-return (
* $string is non-empty-string
* ? positive-int
* : int
* )
*/
function strlen2(string $string) : int { return 1;}
function test(string $s): void {
if (strlen2(strtolower($s))) {
echo 1;
}
}
'
],
];
}
}