From f545bf95bd8f899eec88197176b456e276a89831 Mon Sep 17 00:00:00 2001 From: ElisDN Date: Thu, 8 Jul 2021 14:08:35 +0300 Subject: [PATCH] Fix negative numbers --- src/Psalm/Internal/Type/TypeTokenizer.php | 4 ++++ tests/MagicMethodAnnotationTest.php | 28 +++++++++++++++++++++++ tests/TypeReconciliation/ValueTest.php | 9 ++++++++ 3 files changed, 41 insertions(+) diff --git a/src/Psalm/Internal/Type/TypeTokenizer.php b/src/Psalm/Internal/Type/TypeTokenizer.php index 3267846d91f..5485e5050e9 100644 --- a/src/Psalm/Internal/Type/TypeTokenizer.php +++ b/src/Psalm/Internal/Type/TypeTokenizer.php @@ -384,6 +384,10 @@ public static function getFullyQualifiedTokens( continue; } + if ($string_type_token[0][0] === '-' && is_numeric($string_type_token[0])) { + continue; + } + if (isset($type_tokens[$i + 1]) && $type_tokens[$i + 1][0] === ':' && isset($type_tokens[$i - 1]) diff --git a/tests/MagicMethodAnnotationTest.php b/tests/MagicMethodAnnotationTest.php index 19a573a2429..34e15c9a0b1 100644 --- a/tests/MagicMethodAnnotationTest.php +++ b/tests/MagicMethodAnnotationTest.php @@ -703,6 +703,34 @@ public function __call($method, $attributes) (new \Foo\G)->randomInt(); }' ], + 'negativeInDefault' => [ + 'takesFloat();' + ], + 'namespacedNegativeInDefault' => [ + 'takesFloat(); + }' + ], 'namespacedUnion' => [ ' [ + ' [ '