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

Merge pull request #9339 from edsrzf/is-numeric-negated

This commit is contained in:
Bruce Weirdan 2023-02-19 06:11:10 -04:00 committed by GitHub
commit d934875532
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 0 deletions

View File

@ -1292,6 +1292,10 @@ class SimpleNegatedAssertionReconciler extends Reconciler
} elseif ($type instanceof TArrayKey) {
$redundant = false;
$non_numeric_types[] = new TString();
} elseif ($type instanceof TScalar) {
$redundant = false;
$non_numeric_types[] = new TString();
$non_numeric_types[] = new TBool();
} elseif (!$type->isNumericType()) {
$non_numeric_types[] = $type;
} else {

View File

@ -197,6 +197,20 @@ class ConditionalTest extends TestCase
'$a' => 'string',
],
],
'typeRefinementonWithNegatedIsNumeric' => [
'code' => '<?php
/**
* @param scalar $v
* @return bool|string
*/
function toString($v)
{
if (is_numeric($v)) {
return false;
}
return $v;
}',
],
'typeRefinementWithStringOrTrue' => [
'code' => '<?php
$a = rand(0, 5) > 4 ? "hello" : true;