Skip to content
Permalink
Browse files

Fix #1784 - detect missing end brackets

  • Loading branch information...
muglug committed Jun 15, 2019
1 parent 56e66af commit 41cdde514f41d9f49048e4d63b6e45e77d72cf21
@@ -86,7 +86,7 @@ class Analyzer
/**
* Used to store counts of mixed vs non-mixed variables
*
* @var array<string, array{0: int, 1: int}
* @var array<string, array{0: int, 1: int}>
*/
private $mixed_counts = [];
@@ -531,6 +531,16 @@ public static function createFromTokens(array $type_tokens)
}
}
if ($current_leaf !== $parse_tree
&& ($parse_tree instanceof ParseTree\GenericTree
|| $parse_tree instanceof ParseTree\CallableTree
|| $parse_tree instanceof ParseTree\ObjectLikeTree)
) {
throw new TypeParseTreeException(
'Unterminated bracket'
);
}
return $parse_tree;
}
@@ -43,7 +43,7 @@ public function isTypeContainedByType(string $input, string $container, bool $ex
);
}
/** @return iterable<int,array{string,string,bool} */
/** @return iterable<int,array{string,string,bool}> */
public function typeContainments()
{
yield ['int', 'int|string', true];
@@ -74,7 +74,7 @@ public function canTypeBeContainedByType(string $input, string $container, bool
);
}
/** @return iterable<int,array{string,string,bool} */
/** @return iterable<int,array{string,string,bool}> */
public function typeIntersections()
{
yield ['int', 'int|string', true];
@@ -114,11 +114,11 @@ public function getKeyValueParamsForTraversableObject(string $input, array $expe
);
}
/** @return iterable<int,array{string,array{string,string}} */
/** @return iterable<int,array{string,array{string,string}}> */
public function iterableParams()
{
yield ['iterable<int,string>', ['int', 'string']];
yield ['iterable<int|string,bool|float', ['int|string', 'bool|float']];
yield ['iterable<int|string,bool|float>', ['int|string', 'bool|float']];
}
/**
@@ -100,11 +100,18 @@ public function testNullableOrNullable()
/**
* @return void
*/
public function testArray()
public function testArrayWithClosingBracket()
{
$this->assertSame('array<int, int>', (string) Type::parseString('array<int, int>'));
$this->assertSame('array<int, string>', (string) Type::parseString('array<int, string>'));
$this->assertSame('array<int, static>', (string) Type::parseString('array<int, static>'));
}
/**
* @return void
*/
public function testArrayWithoutClosingBracket()
{
$this->expectException(\Psalm\Exception\TypeParseTreeException::class);
Type::parseString('array<int, int');
}
/**
@@ -317,6 +324,15 @@ public function testObjectLikeWithSimpleArgs()
$this->assertSame('array{a:int, b:string}', (string) Type::parseString('array{a:int, b:string}'));
}
/**
* @return void
*/
public function testObjectLikeWithoutClosingBracket()
{
$this->expectException(\Psalm\Exception\TypeParseTreeException::class);
Type::parseString('array{a:int, b:string');
}
/**
* @return void
*/
@@ -396,6 +412,15 @@ public function testCallable()
);
}
/**
* @return void
*/
public function testCallableWithoutClosingBracket()
{
$this->expectException(\Psalm\Exception\TypeParseTreeException::class);
Type::parseString('callable(int, string');
}
/**
* @return void
*/
@@ -100,7 +100,7 @@ public function testInvalidCode($code, $error_message, $error_levels = [])
}
/**
* @return array<string, array{string,error_levels?:string[]}
* @return array<string, array{string,error_levels?:string[]}>
*/
public function providerValidCodeParse()
{

0 comments on commit 41cdde5

Please sign in to comment.
You can’t perform that action at this time.