1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-22 05:41:20 +01:00

Fix #3365 - add support for negated empty string checks

This commit is contained in:
Brown 2020-05-14 22:09:37 -04:00
parent 6900b12a19
commit ae48c1895f
2 changed files with 20 additions and 0 deletions

View File

@ -338,6 +338,8 @@ class NegatedAssertionReconciler extends Reconciler
$did_remove_type = true;
}
} elseif ($assertion === 'string()') {
$existing_var_type->addType(new Type\Atomic\TNonEmptyString());
}
} elseif ($scalar_type === 'string') {
$scalar_value = substr($assertion, $bracket_pos + 1, -1);

View File

@ -2755,6 +2755,24 @@ class ConditionalTest extends \Psalm\Tests\TestCase
return [$type];
}'
],
'nonEmptyStringAfterLiteralCheck' => [
'<?php
/**
* @param non-empty-string $greeting
*/
function sayHi(string $greeting): void {
echo $greeting;
}
/** @var string */
$hello = "foo";
if ($hello === "") {
throw new \Exception("an empty string is not a greeting");
}
sayHi($hello);',
],
];
}