@@ -643,18 +643,42 @@ private function createArray(array $typeNodes, Context $context): Array_
643643 return new Array_ (...$ types );
644644 }
645645
646- if ($ types [1 ] instanceof Compound && $ types [1 ]->getIterator ()->count () === 2 ) {
647- if ($ this ->validArrayKeyType ($ types [1 ]->get (0 )) && $ this ->validArrayKeyType ($ types [1 ]->get (1 ))) {
648- return new Array_ (...$ types );
649- }
646+ if ($ types [1 ] instanceof Compound) {
647+ for ($ i = 0 ; $ i < $ types [1 ]->getIterator ()->count (); $ i ++) {
648+ if ($ this ->validArrayKeyType ($ types [1 ]->get ($ i ))) {
649+ continue ;
650+ }
651+
652+ throw new RuntimeException ('An array can have only integers or strings as keys ' );
653+ }
654+
655+ return new Array_ (...$ types );
650656 }
651657
652658 throw new RuntimeException ('An array can have only integers or strings as keys ' );
653659 }
654660
655661 private function validArrayKeyType (?Type $ type ): bool
656662 {
657- return $ type instanceof String_ || $ type instanceof Integer;
663+ return $ type instanceof String_ ||
664+ $ type instanceof CallableString ||
665+ $ type instanceof HtmlEscapedString ||
666+ $ type instanceof IntegerRange ||
667+ $ type instanceof IntegerValue ||
668+ $ type instanceof IntMask ||
669+ $ type instanceof IntMaskOf ||
670+ $ type instanceof KeyOf ||
671+ $ type instanceof LiteralString ||
672+ $ type instanceof LowercaseString ||
673+ $ type instanceof NegativeInteger ||
674+ $ type instanceof NonEmptyLowercaseString ||
675+ $ type instanceof NonEmptyString ||
676+ $ type instanceof PositiveInteger ||
677+ $ type instanceof StringValue ||
678+ $ type instanceof ClassString ||
679+ $ type instanceof InterfaceString ||
680+ $ type instanceof TraitString ||
681+ $ type instanceof Integer;
658682 }
659683
660684 private function parse (TokenIterator $ tokenIterator ): TypeNode
0 commit comments