From 95e0614b2e39de3b187a5632bd6a9bc32cb9cf0f Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Sat, 26 Nov 2022 18:44:11 +0100 Subject: [PATCH] Off-by-one fun --- src/Psalm/Type/Atomic/TKeyedArray.php | 2 +- tests/Template/FunctionTemplateTest.php | 2 +- tests/TypeCombinationTest.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Psalm/Type/Atomic/TKeyedArray.php b/src/Psalm/Type/Atomic/TKeyedArray.php index 306102ac9..472a5b062 100644 --- a/src/Psalm/Type/Atomic/TKeyedArray.php +++ b/src/Psalm/Type/Atomic/TKeyedArray.php @@ -340,7 +340,7 @@ class TKeyedArray extends Atomic $value_type = $value_type->setPossiblyUndefined(false); if ($this->fallback_params === null) { - $key_type = new Union([new TIntRange(0, count($this->properties), false, $list_var_id)]); + $key_type = new Union([new TIntRange(0, count($this->properties)-1, false, $list_var_id)]); } else { $key_type = new Union([new TIntRange(0, null, false, $list_var_id)]); } diff --git a/tests/Template/FunctionTemplateTest.php b/tests/Template/FunctionTemplateTest.php index aa58227ee..954156d68 100644 --- a/tests/Template/FunctionTemplateTest.php +++ b/tests/Template/FunctionTemplateTest.php @@ -291,7 +291,7 @@ class FunctionTemplateTest extends TestCase $a = splat_proof(...$foo);', 'assertions' => [ - '$a' => 'array', + '$a' => 'array, int>', ], ], 'passArrayByRef' => [ diff --git a/tests/TypeCombinationTest.php b/tests/TypeCombinationTest.php index b15ae3340..e0a83fd68 100644 --- a/tests/TypeCombinationTest.php +++ b/tests/TypeCombinationTest.php @@ -624,7 +624,7 @@ class TypeCombinationTest extends TestCase ], ], 'combineNonEmptyListWithTKeyedArrayList' => [ - 'list{null|string, ...}', + 'list{null|string, ..., string>}', [ 'non-empty-list', 'array{null}'