mirror of
https://github.com/danog/psalm.git
synced 2024-12-02 09:37:59 +01:00
Fixes
This commit is contained in:
parent
c894b893df
commit
550a7aabad
@ -81,6 +81,8 @@ class FileDiffer
|
||||
{
|
||||
$result = [];
|
||||
for ($d = count($trace) - 1; $d >= 0; --$d) {
|
||||
// Todo: fix integer ranges in fors
|
||||
/** @var int<0, max> $d */
|
||||
$v = $trace[$d];
|
||||
$k = $x - $y;
|
||||
|
||||
|
@ -53,7 +53,7 @@ class PartialParserVisitor extends PhpParser\NodeVisitorAbstract
|
||||
/** @var PhpParser\ErrorHandler\Collecting */
|
||||
private $error_handler;
|
||||
|
||||
/** @param array<int, array{int, int, int, int, int, string}> $offset_map */
|
||||
/** @param array<int, array{0: int, 1: int, 2: int, 3: int, 4: int, 5: string}> $offset_map */
|
||||
public function __construct(
|
||||
PhpParser\Parser $parser,
|
||||
PhpParser\ErrorHandler\Collecting $error_handler,
|
||||
|
@ -30,7 +30,7 @@ class SimpleNameResolver extends NodeVisitorAbstract
|
||||
|
||||
/**
|
||||
* @param ErrorHandler $errorHandler Error handler
|
||||
* @param null|array<int, array{int, int, int, int, int, string}> $offset_map
|
||||
* @param null|array<int, array{0: int, 1: int, 2: int, 3: int, 4: int, 5: string}> $offset_map
|
||||
*/
|
||||
public function __construct(ErrorHandler $errorHandler, ?array $offset_map = null)
|
||||
{
|
||||
|
@ -97,25 +97,6 @@ class ArrayTypeComparator
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($container_type_part instanceof TKeyedArray
|
||||
&& $container_type_part->is_list
|
||||
&& $container_type_part->isNonEmpty()
|
||||
&& $input_type_part instanceof TNonEmptyArray
|
||||
&& $input_type_part->type_params[0]->isSingleIntLiteral()
|
||||
&& $input_type_part->type_params[0]->getSingleIntLiteral()->value === 0
|
||||
) {
|
||||
//this is a special case where the only offset value of an non empty array is 0, so it's a non empty list
|
||||
return UnionTypeComparator::isContainedBy(
|
||||
$codebase,
|
||||
$input_type_part->type_params[1],
|
||||
$container_type_part->getGenericValueType(),
|
||||
$input_type_part->type_params[1]->ignore_nullable_issues,
|
||||
$input_type_part->type_params[1]->ignore_falsable_issues,
|
||||
$atomic_comparison_result,
|
||||
$allow_interface_equality
|
||||
);
|
||||
}
|
||||
|
||||
if ($container_type_part instanceof TKeyedArray) {
|
||||
$container_type_part = $container_type_part->getGenericArrayType();
|
||||
}
|
||||
|
@ -526,7 +526,6 @@ class TypeCombiner
|
||||
}
|
||||
|
||||
foreach ($type->type_params as $i => $type_param) {
|
||||
/** @psalm-suppress InvalidPropertyAssignmentValue */
|
||||
$combination->array_type_params[$i] = Type::combineUnionTypes(
|
||||
$combination->array_type_params[$i] ?? null,
|
||||
$type_param,
|
||||
|
@ -681,6 +681,9 @@ class TypeParser
|
||||
}
|
||||
|
||||
if ($generic_type_value === 'iterable') {
|
||||
if (count($generic_params) > 2) {
|
||||
throw new TypeParseTreeException('Too many template parameters for iterable');
|
||||
}
|
||||
return new TIterable($generic_params, [], $from_docblock);
|
||||
}
|
||||
|
||||
|
@ -240,7 +240,7 @@ trait GenericTrait
|
||||
?Codebase $codebase
|
||||
): ?array {
|
||||
$type_params = $this->type_params;
|
||||
foreach ($type_params as $offset => $type_param) {
|
||||
foreach ($type_params as $offset => &$type_param) {
|
||||
$type_param = TemplateInferredTypeReplacer::replace(
|
||||
$type_param,
|
||||
$template_result,
|
||||
@ -250,9 +250,8 @@ trait GenericTrait
|
||||
if ($this instanceof TArray && $offset === 0 && $type_param->isMixed()) {
|
||||
$type_param = Type::getArrayKey();
|
||||
}
|
||||
|
||||
$type_params[$offset] = $type_param;
|
||||
}
|
||||
unset($type_param);
|
||||
|
||||
return $type_params === $this->type_params ? null : $type_params;
|
||||
}
|
||||
|
@ -398,6 +398,7 @@ class TKeyedArray extends Atomic
|
||||
if ($this->is_list) {
|
||||
foreach ($this->properties as $k => $property) {
|
||||
if ($property->possibly_undefined) {
|
||||
/** @var int<0, max> */
|
||||
return $k;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user