1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-21 21:31:13 +01:00

Fix #328 and allow single-entry object-like shorthand

This commit is contained in:
Matthew Brown 2017-12-18 22:07:52 -05:00
parent ab3b8a0cf2
commit 0e6006deda
3 changed files with 25 additions and 1 deletions

View File

@ -188,7 +188,7 @@ abstract class Type
$type = array_shift($parse_tree->children);
foreach ($parse_tree->children as $i => $property_branch) {
if (!count($property_branch->children)) {
if ($property_branch->value !== ParseTree::OBJECT_PROPERTY) {
$property_type = self::getTypeFromTree($property_branch);
$property_key = (string)$i;
} elseif (count($property_branch->children) === 2) {

View File

@ -149,6 +149,7 @@ class ParseTree
array_pop($current_parent->children);
$current_parent->children[] = $new_parent_leaf;
$has_object_key = true;
break;

View File

@ -5,6 +5,14 @@ use Psalm\Type;
class TypeParseTest extends TestCase
{
/**
* @return void
*/
public function setUp()
{
parent::setUp();
}
/**
* @return void
*/
@ -78,5 +86,20 @@ class TypeParseTest extends TestCase
'array{a:array<int, string|int>, b:string}',
(string) Type::parseString('array{a:array<int, string|int>, b:string}')
);
$this->assertSame(
'array{0:stdClass|null}',
(string)Type::parseString('array{stdClass|null}')
);
$this->assertSame(
'array{0:array<mixed, mixed>}',
(string)Type::parseString('array{array}')
);
$this->assertSame(
'array{0:array<int, string>}',
(string)Type::parseString('array{array<int, string>}')
);
}
}