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:
parent
6900b12a19
commit
ae48c1895f
@ -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);
|
||||
|
@ -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);',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user