From d4df856124b260aeef3df6b2dee58620d5af4274 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Fri, 2 Dec 2022 18:18:26 +0100 Subject: [PATCH] Cleanup --- .../Expression/Call/ArrayFunctionArgumentsAnalyzer.php | 1 + .../Analyzer/Statements/Expression/CallAnalyzer.php | 2 -- .../Internal/Type/SimpleNegatedAssertionReconciler.php | 1 + src/Psalm/Internal/Type/TypeCombiner.php | 1 - src/Psalm/Type/Atomic.php | 6 ++++++ src/Psalm/Type/Atomic/GenericTrait.php | 5 +++-- 6 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArrayFunctionArgumentsAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArrayFunctionArgumentsAnalyzer.php index 5e1595b86..d7a7cd315 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArrayFunctionArgumentsAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArrayFunctionArgumentsAnalyzer.php @@ -554,6 +554,7 @@ class ArrayFunctionArgumentsAnalyzer } else { $properties = $array_atomic_type->properties; unset($properties[$prop_count-1]); + assert($properties !== []); $array_atomic_type = $array_atomic_type->setProperties($properties); } } else { diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/CallAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/CallAnalyzer.php index a2039356d..946baaaa6 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/CallAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/CallAnalyzer.php @@ -494,8 +494,6 @@ class CallAnalyzer * @param PhpParser\Node\Scalar\String_|PhpParser\Node\Expr\Array_|PhpParser\Node\Expr\BinaryOp\Concat $callable_arg * * @return list - * - * @psalm-suppress MoreSpecificReturnType */ public static function getFunctionIdsFromCallableArg( FileSource $file_source, diff --git a/src/Psalm/Internal/Type/SimpleNegatedAssertionReconciler.php b/src/Psalm/Internal/Type/SimpleNegatedAssertionReconciler.php index 5ea4007a7..2dc4ac583 100644 --- a/src/Psalm/Internal/Type/SimpleNegatedAssertionReconciler.php +++ b/src/Psalm/Internal/Type/SimpleNegatedAssertionReconciler.php @@ -550,6 +550,7 @@ class SimpleNegatedAssertionReconciler extends Reconciler $properties []= $array_atomic_type->properties[$x] ?? $array_atomic_type->fallback_params[1]->setPossiblyUndefined(true); } + assert($properties !== []); $existing_var_type->removeType('array'); $existing_var_type->addType(new TKeyedArray( $properties, diff --git a/src/Psalm/Internal/Type/TypeCombiner.php b/src/Psalm/Internal/Type/TypeCombiner.php index 5dcae773c..508cdeaeb 100644 --- a/src/Psalm/Internal/Type/TypeCombiner.php +++ b/src/Psalm/Internal/Type/TypeCombiner.php @@ -574,7 +574,6 @@ class TypeCombiner if ($type instanceof TClassStringMap) { 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] ?? null, $type_param, diff --git a/src/Psalm/Type/Atomic.php b/src/Psalm/Type/Atomic.php index c9e6bdac5..2231e008e 100644 --- a/src/Psalm/Type/Atomic.php +++ b/src/Psalm/Type/Atomic.php @@ -478,6 +478,9 @@ abstract class Atomic implements TypeNode if ($this->hasTraversableInterface($codebase)) { if (strtolower($this->value) === "traversable") { 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([Type::getMixed(), Type::getMixed()]); @@ -488,6 +491,9 @@ abstract class Atomic implements TypeNode $this, 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); } throw new InvalidArgumentException("{$this->getId()} is not an iterable"); diff --git a/src/Psalm/Type/Atomic/GenericTrait.php b/src/Psalm/Type/Atomic/GenericTrait.php index 0bc56987c..d4568475f 100644 --- a/src/Psalm/Type/Atomic/GenericTrait.php +++ b/src/Psalm/Type/Atomic/GenericTrait.php @@ -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,8 +250,9 @@ 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; }