diff --git a/src/Psalm/Internal/Type/TypeParser.php b/src/Psalm/Internal/Type/TypeParser.php index 136c8080081..e77bc710e87 100644 --- a/src/Psalm/Internal/Type/TypeParser.php +++ b/src/Psalm/Internal/Type/TypeParser.php @@ -411,11 +411,12 @@ function (ParseTree $child_tree) use ($codebase, $template_type_map, $type_alias $parse_tree->children ); - $onlyTKeyedArray = true; - $first_type = \reset($intersection_types); $last_type = \end($intersection_types); + $onlyTKeyedArray = $first_type instanceof TKeyedArray + && $last_type instanceof TKeyedArray; + foreach ($intersection_types as $intersection_type) { if (!$intersection_type instanceof TKeyedArray && ($intersection_type !== $first_type diff --git a/tests/TypeParseTest.php b/tests/TypeParseTest.php index e9abb4d9a75..69c753c8955 100644 --- a/tests/TypeParseTest.php +++ b/tests/TypeParseTest.php @@ -203,6 +203,12 @@ public function testIntersectionOfTKeyedArrayWithConflictingProperties(): void Type::parseString('array{a: string}&array{a: int}'); } + public function testIntersectionOfTwoRegularArrays() : void + { + $this->expectException(\Psalm\Exception\TypeParseTreeException::class); + Type::parseString('string[]&array'); + } + public function testUnionOfIntersectionOfTKeyedArray(): void { $this->assertSame('array{a: int|string, b?: int}', (string) Type::parseString('array{a: int}|array{a: string}&array{b: int}'));