mirror of
https://github.com/danog/psalm.git
synced 2025-01-22 13:51:54 +01:00
Fix #4287 - intersection of regular arrays should not result in crash
This commit is contained in:
parent
b0c3f09c29
commit
49dcec6d4a
@ -411,11 +411,12 @@ class TypeParser
|
|||||||
$parse_tree->children
|
$parse_tree->children
|
||||||
);
|
);
|
||||||
|
|
||||||
$onlyTKeyedArray = true;
|
|
||||||
|
|
||||||
$first_type = \reset($intersection_types);
|
$first_type = \reset($intersection_types);
|
||||||
$last_type = \end($intersection_types);
|
$last_type = \end($intersection_types);
|
||||||
|
|
||||||
|
$onlyTKeyedArray = $first_type instanceof TKeyedArray
|
||||||
|
&& $last_type instanceof TKeyedArray;
|
||||||
|
|
||||||
foreach ($intersection_types as $intersection_type) {
|
foreach ($intersection_types as $intersection_type) {
|
||||||
if (!$intersection_type instanceof TKeyedArray
|
if (!$intersection_type instanceof TKeyedArray
|
||||||
&& ($intersection_type !== $first_type
|
&& ($intersection_type !== $first_type
|
||||||
|
@ -203,6 +203,12 @@ class TypeParseTest extends TestCase
|
|||||||
Type::parseString('array{a: string}&array{a: int}');
|
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
|
public function testUnionOfIntersectionOfTKeyedArray(): void
|
||||||
{
|
{
|
||||||
$this->assertSame('array{a: int|string, b?: int}', (string) Type::parseString('array{a: int}|array{a: string}&array{b: int}'));
|
$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