1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Fix parsing of array{a:int}[]

Fixes #614
This commit is contained in:
Matthew Brown 2018-03-22 21:21:04 -04:00
parent b6499c33ed
commit c8fe9e89f3
2 changed files with 35 additions and 1 deletions

View File

@ -50,7 +50,30 @@ class ParseTree
switch ($type_token) {
case '<':
case '{':
throw new TypeParseTreeException('Unexpected token');
case ']':
throw new TypeParseTreeException('Unexpected token ' . $type_token);
case '[':
if ($next_token !== ']') {
throw new TypeParseTreeException('Unexpected token ' . $type_token);
}
$current_parent = $current_leaf->parent;
$new_parent_leaf = new ParseTree\GenericTree('array', $current_parent);
$current_leaf->parent = $new_parent_leaf;
$new_parent_leaf->children = [$current_leaf];
if ($current_parent) {
array_pop($current_parent->children);
$current_parent->children[] = $new_parent_leaf;
} else {
$parse_tree = $new_parent_leaf;
}
$current_leaf = $new_parent_leaf;
++$i;
break;
case '>':
do {

View File

@ -170,6 +170,17 @@ class TypeParseTest extends TestCase
$this->assertSame('array<mixed, array<mixed, A|B>>', (string) Type::parseString('(A|B)[][]'));
}
/**
* @return void
*/
public function testPhpDocObjectLikeArray()
{
$this->assertSame(
'array<mixed, array{b:bool, d:string}>',
(string) Type::parseString('array{b:bool,d:string}[]')
);
}
/**
* @return void
*/