From 73a6fbe5579c33ee70846916a74894723d59ac50 Mon Sep 17 00:00:00 2001 From: Jeffrey Yoo Date: Thu, 1 Aug 2019 16:10:12 -0400 Subject: [PATCH] catch cases of invalid use of backslash (#1983) --- src/Psalm/Type.php | 6 ++++++ tests/AnnotationTest.php | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/Psalm/Type.php b/src/Psalm/Type.php index d83eaffce..e4063bdb6 100644 --- a/src/Psalm/Type.php +++ b/src/Psalm/Type.php @@ -944,6 +944,12 @@ abstract class Type continue; } + if ($string_type_token[0][0] === '\\' + && strlen($string_type_token[0]) === 1 + ) { + throw new TypeParseTreeException("Backslash \"\\\" has to be part of class name."); + } + if ($string_type_token[0][0] === '"' || $string_type_token[0][0] === '\'' || $string_type_token[0] === '0' diff --git a/tests/AnnotationTest.php b/tests/AnnotationTest.php index 2e29e3d51..1686e58f2 100644 --- a/tests/AnnotationTest.php +++ b/tests/AnnotationTest.php @@ -1195,6 +1195,16 @@ class AnnotationTest extends TestCase }', 'error_message' => 'InvalidDocblock - src' . DIRECTORY_SEPARATOR . 'somefile.php:5:21 - Badly-formatted @param', ], + 'invalidSlashWithString' => [ + ' 'InvalidDocblock', + ], 'missingReturnTypeWithBadDocblock' => [ '