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

simplify reconciliation of literal ints with inferior/superior assertions

This commit is contained in:
orklah 2021-12-08 22:13:19 +01:00
parent be9037f7b1
commit edeaada8af
2 changed files with 6 additions and 12 deletions

View File

@ -1638,8 +1638,7 @@ class SimpleAssertionReconciler extends Reconciler
}
$existing_var_type->addType($atomic_type);
} elseif ($atomic_type instanceof Atomic\TLiteralInt) {
$new_range = new Atomic\TIntRange($assertion_value, null);
if (!$new_range->contains($atomic_type->value)) {
if ($atomic_type->value < $assertion_value) {
$existing_var_type->removeType($atomic_type->getKey());
} /*elseif ($inside_loop) {
//when inside a loop, allow the range to extends the type
@ -1684,10 +1683,9 @@ class SimpleAssertionReconciler extends Reconciler
}
$existing_var_type->addType($atomic_type);
} elseif ($atomic_type instanceof Atomic\TLiteralInt) {
$new_range = new Atomic\TIntRange(null, $assertion_value);
if (!$new_range->contains($atomic_type->value)) {
if ($atomic_type->value > $assertion_value) {
$existing_var_type->removeType($atomic_type->getKey());
}/* elseif ($inside_loop) {
} /* elseif ($inside_loop) {
//when inside a loop, allow the range to extends the type
$existing_var_type->removeType($atomic_type->getKey());
if ($atomic_type->value < $assertion_value) {

View File

@ -1519,9 +1519,7 @@ class SimpleNegatedAssertionReconciler extends Reconciler
}
$existing_var_type->addType($atomic_type);
} elseif ($atomic_type instanceof Atomic\TLiteralInt) {
$new_range = new Atomic\TIntRange(null, $assertion_value);
if (!$new_range->contains($atomic_type->value)) {
//emit an issue here in the future about incompatible type
if ($atomic_type->value > $assertion_value) {
$existing_var_type->removeType($atomic_type->getKey());
} /*elseif ($inside_loop) {
//when inside a loop, allow the range to extends the type
@ -1563,11 +1561,9 @@ class SimpleNegatedAssertionReconciler extends Reconciler
}
$existing_var_type->addType($atomic_type);
} elseif ($atomic_type instanceof Atomic\TLiteralInt) {
$new_range = new Atomic\TIntRange($assertion_value, null);
if (!$new_range->contains($atomic_type->value)) {
//emit an issue here in the future about incompatible type
if ($atomic_type->value < $assertion_value) {
$existing_var_type->removeType($atomic_type->getKey());
}/* elseif ($inside_loop) {
} /* elseif ($inside_loop) {
//when inside a loop, allow the range to extends the type
$existing_var_type->removeType($atomic_type->getKey());
if ($atomic_type->value < $assertion_value) {