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:
parent
2564abde85
commit
96768ffd48
@ -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;
|
||||
}
|
||||
|
@ -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',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user