Skip to content

Commit

Permalink
Merge pull request #6064 from ElisDN/negative-numbers
Browse files Browse the repository at this point in the history
Negative number literals
  • Loading branch information
weirdan authored Jul 8, 2021
2 parents bbbfa69 + 61b78e1 commit 04c9d60
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Psalm/Internal/Type/TypeTokenizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
28 changes: 28 additions & 0 deletions tests/MagicMethodAnnotationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,34 @@ public function __call($method, $attributes)
(new \Foo\G)->randomInt();
}'
],
'negativeInDefault' => [
'<?php
/**
* @method void foo($a = -0.1, $b = -12)
*/
class G
{
public function __call(string $method, array $attributes): void
{
}
}
(new G)->foo();'
],
'namespacedNegativeInDefault' => [
'<?php
namespace Foo {
/**
* @method void foo($a = -0.1, $b = -12)
*/
class G
{
public function __call(string $method, array $attributes): void
{
}
}
(new G)->foo();
}'
],
'namespacedUnion' => [
'<?php
namespace Foo;
Expand Down
9 changes: 9 additions & 0 deletions tests/TypeReconciliation/ValueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,15 @@ class A {
private $type = "easy";
}'
],
'supportMultipleValues' => [
'<?php
class A {
/**
* @var 0|-1|1
*/
private $type = -1;
}'
],
'typecastTrueToInt' => [
'<?php
/**
Expand Down

0 comments on commit 04c9d60

Please sign in to comment.