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:
parent
c8d4bafb85
commit
1f2d2764ab
@ -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
|
||||
|
@ -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}'));
|
||||
|
Loading…
x
Reference in New Issue
Block a user