From 4df995f23344d5d11cbfd7ca3f17e05ecb0435c9 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sun, 14 Nov 2021 21:08:40 +0000 Subject: [PATCH 1/6] Acknowledge that array may still have integer keys --- src/Type/ArrayType.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Type/ArrayType.php b/src/Type/ArrayType.php index b8487cde25..4e87f551a2 100644 --- a/src/Type/ArrayType.php +++ b/src/Type/ArrayType.php @@ -176,7 +176,7 @@ public function getIterableKeyType(): Type if ($keyType instanceof MixedType && !$keyType instanceof TemplateMixedType) { return new BenevolentUnionType([new IntegerType(), new StringType()]); } - if ($keyType instanceof StrictMixedType) { + if ($keyType instanceof StrictMixedType || $keyType instanceof StringType) { return new BenevolentUnionType([new IntegerType(), new StringType()]); } From 144266a52f422faceb099552448f51734d901326 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 15 Nov 2021 17:28:26 +0000 Subject: [PATCH 2/6] Don't wipe out ConstantString or ClassString types --- src/Type/ArrayType.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Type/ArrayType.php b/src/Type/ArrayType.php index 4e87f551a2..41a88a6cf6 100644 --- a/src/Type/ArrayType.php +++ b/src/Type/ArrayType.php @@ -176,8 +176,11 @@ public function getIterableKeyType(): Type if ($keyType instanceof MixedType && !$keyType instanceof TemplateMixedType) { return new BenevolentUnionType([new IntegerType(), new StringType()]); } - if ($keyType instanceof StrictMixedType || $keyType instanceof StringType) { - return new BenevolentUnionType([new IntegerType(), new StringType()]); + if ($keyType instanceof StrictMixedType) { + return new UnionType([new IntegerType(), new StringType()]); + } + if ($keyType instanceof StringType) { + return new UnionType([new IntegerType, $keyType]); } return $keyType; From 12c6894f6d71a1cedb2ff6351ca055f226fb7025 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 15 Nov 2021 17:29:18 +0000 Subject: [PATCH 3/6] fixed oops --- src/Type/ArrayType.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Type/ArrayType.php b/src/Type/ArrayType.php index 41a88a6cf6..5e75299992 100644 --- a/src/Type/ArrayType.php +++ b/src/Type/ArrayType.php @@ -177,7 +177,7 @@ public function getIterableKeyType(): Type return new BenevolentUnionType([new IntegerType(), new StringType()]); } if ($keyType instanceof StrictMixedType) { - return new UnionType([new IntegerType(), new StringType()]); + return new BenevolentUnionType([new IntegerType(), new StringType()]); } if ($keyType instanceof StringType) { return new UnionType([new IntegerType, $keyType]); From 48ffb02f335e624da073f90d8d792e1798aa0df3 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 15 Nov 2021 17:48:46 +0000 Subject: [PATCH 4/6] Only add int to the type if the keys may be numeric strings also, class-string->isNumericString() is maybe? wtf? --- src/Type/ArrayType.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Type/ArrayType.php b/src/Type/ArrayType.php index 5e75299992..979242cd96 100644 --- a/src/Type/ArrayType.php +++ b/src/Type/ArrayType.php @@ -179,7 +179,7 @@ public function getIterableKeyType(): Type if ($keyType instanceof StrictMixedType) { return new BenevolentUnionType([new IntegerType(), new StringType()]); } - if ($keyType instanceof StringType) { + if (!$keyType->isNumericString()->no()) { return new UnionType([new IntegerType, $keyType]); } From 5f30c32342098cb860a2c8398396244bab0af75d Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 15 Nov 2021 18:40:13 +0000 Subject: [PATCH 5/6] TypeCombinator --- src/Type/ArrayType.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Type/ArrayType.php b/src/Type/ArrayType.php index 979242cd96..6c0859a6ef 100644 --- a/src/Type/ArrayType.php +++ b/src/Type/ArrayType.php @@ -180,7 +180,7 @@ public function getIterableKeyType(): Type return new BenevolentUnionType([new IntegerType(), new StringType()]); } if (!$keyType->isNumericString()->no()) { - return new UnionType([new IntegerType, $keyType]); + return TypeCombinator::union(new IntegerType, $keyType); } return $keyType; From 79881377480a2c1623f88ed8b34d5007e421937b Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 15 Nov 2021 18:42:24 +0000 Subject: [PATCH 6/6] shut --- src/Type/ArrayType.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Type/ArrayType.php b/src/Type/ArrayType.php index 6c0859a6ef..563beb29ee 100644 --- a/src/Type/ArrayType.php +++ b/src/Type/ArrayType.php @@ -180,7 +180,7 @@ public function getIterableKeyType(): Type return new BenevolentUnionType([new IntegerType(), new StringType()]); } if (!$keyType->isNumericString()->no()) { - return TypeCombinator::union(new IntegerType, $keyType); + return TypeCombinator::union(new IntegerType(), $keyType); } return $keyType;