1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-11 16:59:45 +01:00
This commit is contained in:
Daniil Gentili 2022-12-02 18:18:26 +01:00
parent 8f2a8c0746
commit d4df856124
6 changed files with 11 additions and 5 deletions

View File

@ -554,6 +554,7 @@ class ArrayFunctionArgumentsAnalyzer
} else { } else {
$properties = $array_atomic_type->properties; $properties = $array_atomic_type->properties;
unset($properties[$prop_count-1]); unset($properties[$prop_count-1]);
assert($properties !== []);
$array_atomic_type = $array_atomic_type->setProperties($properties); $array_atomic_type = $array_atomic_type->setProperties($properties);
} }
} else { } else {

View File

@ -494,8 +494,6 @@ class CallAnalyzer
* @param PhpParser\Node\Scalar\String_|PhpParser\Node\Expr\Array_|PhpParser\Node\Expr\BinaryOp\Concat $callable_arg * @param PhpParser\Node\Scalar\String_|PhpParser\Node\Expr\Array_|PhpParser\Node\Expr\BinaryOp\Concat $callable_arg
* *
* @return list<non-empty-string> * @return list<non-empty-string>
*
* @psalm-suppress MoreSpecificReturnType
*/ */
public static function getFunctionIdsFromCallableArg( public static function getFunctionIdsFromCallableArg(
FileSource $file_source, FileSource $file_source,

View File

@ -550,6 +550,7 @@ class SimpleNegatedAssertionReconciler extends Reconciler
$properties []= $array_atomic_type->properties[$x] $properties []= $array_atomic_type->properties[$x]
?? $array_atomic_type->fallback_params[1]->setPossiblyUndefined(true); ?? $array_atomic_type->fallback_params[1]->setPossiblyUndefined(true);
} }
assert($properties !== []);
$existing_var_type->removeType('array'); $existing_var_type->removeType('array');
$existing_var_type->addType(new TKeyedArray( $existing_var_type->addType(new TKeyedArray(
$properties, $properties,

View File

@ -574,7 +574,6 @@ class TypeCombiner
if ($type instanceof TClassStringMap) { if ($type instanceof TClassStringMap) {
foreach ([$type->getStandinKeyParam(), $type->value_param] as $i => $type_param) { foreach ([$type->getStandinKeyParam(), $type->value_param] as $i => $type_param) {
/** @psalm-suppress InvalidPropertyAssignmentValue */
$combination->array_type_params[$i] = Type::combineUnionTypes( $combination->array_type_params[$i] = Type::combineUnionTypes(
$combination->array_type_params[$i] ?? null, $combination->array_type_params[$i] ?? null,
$type_param, $type_param,

View File

@ -478,6 +478,9 @@ abstract class Atomic implements TypeNode
if ($this->hasTraversableInterface($codebase)) { if ($this->hasTraversableInterface($codebase)) {
if (strtolower($this->value) === "traversable") { if (strtolower($this->value) === "traversable") {
if ($this instanceof TGenericObject) { if ($this instanceof TGenericObject) {
if (count($this->type_params) > 2) {
throw new InvalidArgumentException('Too many templates!');
}
return new TIterable($this->type_params); return new TIterable($this->type_params);
} }
return new TIterable([Type::getMixed(), Type::getMixed()]); return new TIterable([Type::getMixed(), Type::getMixed()]);
@ -488,6 +491,9 @@ abstract class Atomic implements TypeNode
$this, $this,
new TGenericObject("Traversable", [Type::getMixed(), Type::getMixed()]), new TGenericObject("Traversable", [Type::getMixed(), Type::getMixed()]),
); );
if (count($implemented_traversable_templates) > 2) {
throw new InvalidArgumentException('Too many templates!');
}
return new TIterable($implemented_traversable_templates); return new TIterable($implemented_traversable_templates);
} }
throw new InvalidArgumentException("{$this->getId()} is not an iterable"); throw new InvalidArgumentException("{$this->getId()} is not an iterable");

View File

@ -240,7 +240,7 @@ trait GenericTrait
?Codebase $codebase ?Codebase $codebase
): ?array { ): ?array {
$type_params = $this->type_params; $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 = TemplateInferredTypeReplacer::replace(
$type_param, $type_param,
$template_result, $template_result,
@ -250,8 +250,9 @@ trait GenericTrait
if ($this instanceof TArray && $offset === 0 && $type_param->isMixed()) { if ($this instanceof TArray && $offset === 0 && $type_param->isMixed()) {
$type_param = Type::getArrayKey(); $type_param = Type::getArrayKey();
} }
$type_params[$offset] = $type_param;
} }
unset($type_param);
return $type_params === $this->type_params ? null : $type_params; return $type_params === $this->type_params ? null : $type_params;
} }