1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-22 05:41:20 +01:00

Fix #617 - catch exception on bad square brackets

This commit is contained in:
Matthew Brown 2018-03-24 21:02:44 -04:00
parent f5ef864168
commit 74aa376ec7
3 changed files with 36 additions and 0 deletions

View File

@ -60,6 +60,8 @@ abstract class Type
$parsed_type = self::getTypeFromTree($parse_tree, $php_compatible);
} catch (TypeParseTreeException $e) {
throw $e;
} catch (\Exception $e) {
throw new TypeParseTreeException($e->getMessage());
}
if (!($parsed_type instanceof Union)) {

View File

@ -116,6 +116,10 @@ abstract class Atomic
throw new \Psalm\Exception\TypeParseTreeException('no hyphens allowed');
}
if (is_numeric($value[0])) {
throw new \Psalm\Exception\TypeParseTreeException('First character of type cannot be numeric');
}
return new TNamedObject($value);
}
}

View File

@ -765,6 +765,36 @@ class AnnotationTest extends TestCase
}',
'error_message' => 'InvalidDocblock',
],
'invalidReturnBrackets' => [
'<?php
interface I {
/**
* @return []
*/
public static function barBar();
}',
'error_message' => 'InvalidDocblock',
],
'invalidPropertyClass' => [
'<?php
class A {
/**
* @var 1
*/
public $bar;
}',
'error_message' => 'InvalidDocblock',
],
'invalidPropertyBrackets' => [
'<?php
class A {
/**
* @var []
*/
public $bar;
}',
'error_message' => 'InvalidDocblock',
],
'invalidReturnClassWithComma' => [
'<?php
interface I {