1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Fix wrong redundant condition converting scalar to string

This commit is contained in:
Matthew Brown 2018-10-10 01:57:11 -04:00
parent 2564abde85
commit 96768ffd48
2 changed files with 39 additions and 0 deletions

View File

@ -624,6 +624,9 @@ class Reconciler
foreach ($existing_var_atomic_types as $type) {
if ($type instanceof TBool) {
$bool_types[] = $type;
} elseif ($type instanceof TScalar) {
$bool_types[] = new TBool;
$did_remove_type = true;
} else {
$did_remove_type = true;
}
@ -1059,6 +1062,10 @@ class Reconciler
|| ($is_equality && get_class($type) === TBool::class)
) {
$non_bool_types[] = $type;
if ($type instanceof TScalar) {
$did_remove_type = true;
}
} else {
$did_remove_type = true;
}

View File

@ -1048,6 +1048,24 @@ class TypeReconciliationTest extends TestCase
if (!$f) {}
}',
],
'scalarToBool' => [
'<?php
/** @param mixed $s */
function foo($s) : void {
if (!is_scalar($s)) {
return;
}
if (is_bool($s)) {}
if (!is_bool($s)) {}
if (is_string($s)) {}
if (!is_string($s)) {}
if (is_int($s)) {}
if (!is_int($s)) {}
if (is_float($s)) {}
if (!is_float($s)) {}
}',
],
];
}
@ -1247,6 +1265,20 @@ class TypeReconciliationTest extends TestCase
}',
'error_message' => 'TypeDoesNotContainType',
],
'scalarToBoolContradiction' => [
'<?php
/** @param mixed $s */
function foo($s) : void {
if (!is_scalar($s)) {
return;
}
if (!is_bool($s)) {
if (is_bool($s)) {}
}
}',
'error_message' => 'ParadoxicalCondition',
],
];
}
}