mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
parent
dc82243edc
commit
8becefda04
@ -635,6 +635,12 @@ class ParseTree
|
||||
case '::':
|
||||
$nexter_token = $i + 2 < $c ? $type_tokens[$i + 2] : null;
|
||||
|
||||
if ($current_leaf instanceof ParseTree\ObjectLikeTree) {
|
||||
throw new TypeParseTreeException(
|
||||
'Unexpected :: in array key'
|
||||
);
|
||||
}
|
||||
|
||||
if (!$nexter_token
|
||||
|| (!preg_match('/^([a-zA-Z_][a-zA-Z_0-9]*\*?|\*)$/', $nexter_token[0])
|
||||
&& strtolower($nexter_token[0]) !== 'class')
|
||||
|
@ -80,7 +80,7 @@ class ObjectLike extends \Psalm\Type\Atomic
|
||||
return (string) $type;
|
||||
}
|
||||
|
||||
if (\is_string($name) && \preg_match('/[ "\'\\\\.\n]/', $name)) {
|
||||
if (\is_string($name) && \preg_match('/[ "\'\\\\.\n:]/', $name)) {
|
||||
$name = '\'' . \str_replace("\n", '\n', \addslashes($name)) . '\'';
|
||||
}
|
||||
|
||||
@ -106,7 +106,7 @@ class ObjectLike extends \Psalm\Type\Atomic
|
||||
return $type->getId();
|
||||
}
|
||||
|
||||
if (\is_string($name) && \preg_match('/[ "\'\\\\.\n]/', $name)) {
|
||||
if (\is_string($name) && \preg_match('/[ "\'\\\\.\n:]/', $name)) {
|
||||
$name = '\'' . \str_replace("\n", '\n', \addslashes($name)) . '\'';
|
||||
}
|
||||
|
||||
@ -164,7 +164,7 @@ class ObjectLike extends \Psalm\Type\Atomic
|
||||
$this_class,
|
||||
$use_phpdoc_format
|
||||
) {
|
||||
if (\is_string($name) && \preg_match('/[ "\'\\\\.\n]/', $name)) {
|
||||
if (\is_string($name) && \preg_match('/[ "\'\\\\.\n:]/', $name)) {
|
||||
$name = '\'' . \str_replace("\n", '\n', \addslashes($name)) . '\'';
|
||||
}
|
||||
|
||||
|
@ -426,6 +426,23 @@ class TypeParseTest extends TestCase
|
||||
$this->assertSame('array{\'\\"\': int, \'\\\'\': string}', (string) Type:: parseString('array{"\\"": int, "\\\'": string}'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testObjectLikeWithClassConstantKey()
|
||||
{
|
||||
$this->expectException(\Psalm\Exception\TypeParseTreeException::class);
|
||||
Type::parseString('array{self::FOO: string}');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testObjectLikeWithQuotedClassConstantKey()
|
||||
{
|
||||
$this->assertSame('array{\'self::FOO\': string}', (string) Type:: parseString('array{"self::FOO": string}'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user