Skip to content

Commit

Permalink
apply patch
Browse files Browse the repository at this point in the history
  • Loading branch information
orklah committed Jan 5, 2022
1 parent 2d9b798 commit 135bee9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
24 changes: 9 additions & 15 deletions src/Psalm/Internal/Type/ParseTreeCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -746,22 +746,16 @@ private function handleValue(array $type_token): void
break;

case '{':
$nexter_token = $this->t + 2 < $this->type_token_count ? $this->type_tokens[$this->t + 2] : null;
$new_leaf = new KeyedArrayTree(
$type_token[0],
$new_parent
);
++$this->t;

if ($nexter_token[0] === '}') {
$new_leaf = new Value(
'array<never, never>',
$type_token[1],
$type_token[1] + strlen($type_token[0]),
$type_token[2] ?? null,
$new_parent
);
$this->t += 2;
} else {
$new_leaf = new KeyedArrayTree(
$type_token[0],
$new_parent
);
$nexter_token = $this->t + 1 < $this->type_token_count ? $this->type_tokens[$this->t + 1] : null;

if ($nexter_token !== null && $nexter_token[0] === '}') {
$new_leaf->terminated = true;
++$this->t;
}
break;
Expand Down
4 changes: 2 additions & 2 deletions src/Psalm/Internal/Type/TypeParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -1233,7 +1233,7 @@ private static function getTypeFromIndexAccessTree(
/**
* @param array<string, array<string, Union>> $template_type_map
* @param array<string, TypeAlias> $type_aliases
* @return TCallableKeyedArray|TKeyedArray|TObjectWithProperties
* @return TCallableKeyedArray|TKeyedArray|TObjectWithProperties|TArray
* @throws TypeParseTreeException
*/
private static function getTypeFromKeyedArrayTree(
Expand Down Expand Up @@ -1312,7 +1312,7 @@ private static function getTypeFromKeyedArrayTree(
}

if (!$properties) {
throw new TypeParseTreeException('No properties supplied for TKeyedArray');
return new TArray([Type::getNever(), Type::getNever()]);
}

if ($type === 'object') {
Expand Down
8 changes: 8 additions & 0 deletions tests/TypeParseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,14 @@ public function testSingleLiteralString(): void
);
}

public function testEmptyArrayShape(): void
{
$this->assertSame(
'array<never, never>',
(string)Type::parseString('array{}')
);
}

public function testSingleLiteralInt(): void
{
$this->assertSame(
Expand Down

0 comments on commit 135bee9

Please sign in to comment.