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:
commit
db8f7180dc
@ -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,
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
'
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user