Skip to content

Commit

Permalink
Merge pull request #9491 from weirdan/support-numeric-literal-separat…
Browse files Browse the repository at this point in the history
…ors-in-docblocks
  • Loading branch information
weirdan committed Mar 15, 2023
2 parents 8d71479 + b37c566 commit 9b00049
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Psalm/Internal/Type/TypeParser.php
Expand Up @@ -91,6 +91,7 @@
use function strlen;
use function strpos;
use function strtolower;
use function strtr;
use function substr;

/**
Expand Down Expand Up @@ -420,8 +421,8 @@ public static function getTypeFromTree(
return new TLiteralFloat((float) $parse_tree->value, $from_docblock);
}

if (preg_match('/^\-?(0|[1-9][0-9]*)$/', $parse_tree->value)) {
return new TLiteralInt((int) $parse_tree->value, $from_docblock);
if (preg_match('/^\-?(0|[1-9]([0-9_]*[0-9])?)$/', $parse_tree->value)) {
return new TLiteralInt((int) strtr($parse_tree->value, ['_' => '']), $from_docblock);
}

if (!preg_match('@^(\$this|\\\\?[a-zA-Z_\x7f-\xff][\\\\\-0-9a-zA-Z_\x7f-\xff]*)$@', $parse_tree->value)) {
Expand Down
20 changes: 20 additions & 0 deletions tests/TypeParseTest.php
Expand Up @@ -1032,6 +1032,26 @@ public function testSingleLiteralInt(): void
);
}

public function testSingleLiteralIntWithSeparators(): void
{
$this->assertSame('10', Type::parseString('1_0')->getId());
}

public function testIntRangeWithSeparators(): void
{
$this->assertSame('int<10, 20>', Type::parseString('int<1_0, 2_0>')->getId());
}

public function testLiteralIntUnionWithSeparators(): void
{
$this->assertSame('10|20', Type::parseString('1_0|2_0')->getId());
}

public function testIntMaskWithIntsWithSeparators(): void
{
$this->assertSame('0|10|20|30', Type::parseString('int-mask<1_0, 2_0>')->getId());
}

public function testSingleLiteralFloat(): void
{
$this->assertSame(
Expand Down

0 comments on commit 9b00049

Please sign in to comment.