1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-21 21:31:13 +01:00

Fix #2827 - detect literal numeric values

This commit is contained in:
Matthew Brown 2020-02-22 00:16:15 -05:00
parent 4707b21227
commit 9f13341ef9
2 changed files with 17 additions and 0 deletions

View File

@ -1404,6 +1404,9 @@ class TypeAnalyzer
&& ($container_type_part instanceof TNumericString
|| $container_type_part instanceof THtmlEscapedString)
) {
if ($input_type_part instanceof TLiteralString) {
return is_numeric($input_type_part->value);
}
if ($atomic_comparison_result) {
$atomic_comparison_result->type_coerced = true;
}

View File

@ -646,6 +646,20 @@ class ValueTest extends TestCase
return false;
}'
],
'numericStringValue' => [
'<?php
/** @psalm-return numeric-string */
function makeNumeric() : string {
return "12.34";
}
/** @psalm-param numeric-string $string */
function consumeNumeric(string $string) : void {
\error_log($string);
}
consumeNumeric("12.34");'
],
];
}