diff --git a/src/TypeResolver.php b/src/TypeResolver.php index 32c8755..58af0ac 100644 --- a/src/TypeResolver.php +++ b/src/TypeResolver.php @@ -551,13 +551,24 @@ private function createArray(array $typeNodes, Context $context): Array_ return new Array_(...$types); } - if ($types[1] instanceof String_ || $types[1] instanceof Integer || $types[1] instanceof ArrayKey) { + if ($this->validArrayKeyType($types[1]) || $types[1] instanceof ArrayKey) { return new Array_(...$types); } + if ($types[1] instanceof Compound && $types[1]->getIterator()->count() === 2) { + if ($this->validArrayKeyType($types[1]->get(0)) && $this->validArrayKeyType($types[1]->get(1))) { + return new Array_(...$types); + } + } + throw new RuntimeException('An array can have only integers or strings as keys'); } + private function validArrayKeyType(?Type $type): bool + { + return $type instanceof String_ || $type instanceof Integer; + } + private function parse(TokenIterator $tokenIterator): TypeNode { try { diff --git a/tests/unit/TypeResolverTest.php b/tests/unit/TypeResolverTest.php index efb405b..eac321d 100644 --- a/tests/unit/TypeResolverTest.php +++ b/tests/unit/TypeResolverTest.php @@ -960,6 +960,18 @@ public function genericsProvider(): array new Integer() ), ], + [ + 'array', + new Array_( + new Object_(new Fqsen('\\phpDocumentor\\Foo\\Bar')), + new Compound( + [ + new String_(), + new Integer(), + ] + ) + ), + ], [ 'Collection[]', new Array_(