Skip to content

Commit

Permalink
Fix negative numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
ElisDN committed Jul 8, 2021
1 parent bbbfa69 commit f545bf9
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 takesFloat($a = -0.1, $b = -1)
*/
class G
{
public function __call(string $method, array $attributes): void
{
}
}
(new G)->takesFloat();'
],
'namespacedNegativeInDefault' => [
'<?php
namespace Foo {
/**
* @method void takesFloat($a = -0.1, $b = -1)
*/
class G
{
public function __call(string $method, array $attributes): void
{
}
}
(new G)->takesFloat();
}'
],
'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 f545bf9

Please sign in to comment.