1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-22 05:41:20 +01:00

Fix #4287 - intersection of regular arrays should not result in crash

This commit is contained in:
Matt Brown 2020-10-07 17:47:17 -04:00
parent c8d4bafb85
commit 1f2d2764ab
2 changed files with 9 additions and 2 deletions

View File

@ -411,11 +411,12 @@ class TypeParser
$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

View File

@ -203,6 +203,12 @@ class TypeParseTest extends TestCase
Type::parseString('array{a: string}&array{a: int}');
}
public function testIntersectionOfTwoRegularArrays() : void
{
$this->expectException(\Psalm\Exception\TypeParseTreeException::class);
Type::parseString('string[]&array<string, string>');
}
public function testUnionOfIntersectionOfTKeyedArray(): void
{
$this->assertSame('array{a: int|string, b?: int}', (string) Type::parseString('array{a: int}|array{a: string}&array{b: int}'));