Skip to content

Commit

Permalink
Prevent invalid [] brackets in tree
Browse files Browse the repository at this point in the history
Fixes #3246
  • Loading branch information
muglug committed Apr 28, 2020
1 parent a402d45 commit 05ff8d0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Psalm/Internal/Type/ParseTree.php
Expand Up @@ -103,6 +103,10 @@ public static function createFromTokens(array $type_tokens)

$new_parent_leaf = new ParseTree\IndexedAccessTree($next_token[0], $current_parent);
} else {
if ($current_leaf instanceof ParseTree\ObjectLikePropertyTree) {
throw new TypeParseTreeException('Unexpected token ' . $type_token[0]);
}

$new_parent_leaf = new ParseTree\GenericTree('array', $current_parent);
}

Expand Down
9 changes: 9 additions & 0 deletions tests/TypeParseTest.php
Expand Up @@ -424,6 +424,15 @@ public function testObjectLikeWithoutClosingBracket()
Type::parseString('array{a: int, b: string');
}

/**
* @return void
*/
public function testObjectLikeArrayInType()
{
$this->expectException(\Psalm\Exception\TypeParseTreeException::class);
Type::parseString('array{a:[]}');
}

/**
* @return void
*/
Expand Down

0 comments on commit 05ff8d0

Please sign in to comment.