Skip to content

Commit

Permalink
Fix #4154 - treat literal numeric strings as numeric
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Sep 8, 2020
1 parent b84ef43 commit 712a222
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Psalm/Type/Atomic.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
use Psalm\Type\Atomic\TIterable;
use Psalm\Type\Atomic\TList;
use Psalm\Type\Atomic\TLiteralClassString;
use Psalm\Type\Atomic\TliteralString;
use Psalm\Type\Atomic\TMixed;
use Psalm\Type\Atomic\TNamedObject;
use Psalm\Type\Atomic\TNever;
Expand Down Expand Up @@ -289,7 +290,8 @@ public function isNumericType(): bool
return $this instanceof TInt
|| $this instanceof TFloat
|| $this instanceof TNumericString
|| $this instanceof TNumeric;
|| $this instanceof TNumeric
|| ($this instanceof TLiteralString && \is_numeric($this->value));
}

public function isObjectType(): bool
Expand Down
8 changes: 8 additions & 0 deletions tests/TypeReconciliation/ReconcilerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,14 @@ public function providerTestTypeIsContainedBy()
'array<empty, empty>',
'array{a?: string, b?: string}',
],
'literalNumericStringInt' => [
'"0"',
'numeric',
],
'literalNumericString' => [
'"10.03"',
'numeric',
],
];
}
}

0 comments on commit 712a222

Please sign in to comment.