mirror of
https://github.com/danog/psalm.git
synced 2024-11-26 20:34:47 +01:00
Convert numeric literal strings to their int/float equivalents for numeric operations
This commit is contained in:
parent
f1be27b18a
commit
8d63dfec0a
@ -547,6 +547,22 @@ class NonDivArithmeticOpAnalyzer
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($left_type_part instanceof Type\Atomic\TLiteralString) {
|
||||
if (preg_match('/^\-?\d+$/', $left_type_part->value)) {
|
||||
$left_type_part = new Type\Atomic\TLiteralInt((int) $left_type_part->value);
|
||||
} elseif (preg_match('/^\-?\d?\.\d+$/', $left_type_part->value)) {
|
||||
$left_type_part = new Type\Atomic\TLiteralFloat((float) $left_type_part->value);
|
||||
}
|
||||
}
|
||||
|
||||
if ($right_type_part instanceof Type\Atomic\TLiteralString) {
|
||||
if (preg_match('/^\-?\d+$/', $right_type_part->value)) {
|
||||
$right_type_part = new Type\Atomic\TLiteralInt((int) $right_type_part->value);
|
||||
} elseif (preg_match('/^\-?\d?\.\d+$/', $right_type_part->value)) {
|
||||
$right_type_part = new Type\Atomic\TLiteralFloat((float) $right_type_part->value);
|
||||
}
|
||||
}
|
||||
|
||||
if ($left_type_part->isNumericType() || $right_type_part->isNumericType()) {
|
||||
if (($left_type_part instanceof TNumeric || $right_type_part instanceof TNumeric)
|
||||
&& ($left_type_part->isNumericType() && $right_type_part->isNumericType())
|
||||
|
Loading…
Reference in New Issue
Block a user