mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
fix reconciliation between positive-int and inferior/superior assertions
This commit is contained in:
parent
b65e37c5f9
commit
be9037f7b1
@ -1651,11 +1651,10 @@ class SimpleAssertionReconciler extends Reconciler
|
||||
}
|
||||
}*/
|
||||
} elseif ($atomic_type instanceof Atomic\TPositiveInt) {
|
||||
if ($assertion_value <= 0) {
|
||||
//emit an issue here in the future about incompatible type
|
||||
if ($assertion_value > 1) {
|
||||
$existing_var_type->removeType($atomic_type->getKey());
|
||||
$existing_var_type->addType(new Atomic\TIntRange($assertion_value, null));
|
||||
}
|
||||
$existing_var_type->removeType($atomic_type->getKey());
|
||||
$existing_var_type->addType(new Atomic\TIntRange($assertion_value, null));
|
||||
} elseif ($atomic_type instanceof TInt) {
|
||||
$existing_var_type->removeType($atomic_type->getKey());
|
||||
$existing_var_type->addType(new Atomic\TIntRange($assertion_value, null));
|
||||
@ -1698,11 +1697,10 @@ class SimpleAssertionReconciler extends Reconciler
|
||||
}
|
||||
}*/
|
||||
} elseif ($atomic_type instanceof Atomic\TPositiveInt) {
|
||||
if ($assertion_value <= 0) {
|
||||
//emit an issue here in the future about incompatible type
|
||||
}
|
||||
$existing_var_type->removeType($atomic_type->getKey());
|
||||
$existing_var_type->addType(new Atomic\TIntRange(1, $assertion_value));
|
||||
if ($assertion_value >= 1) {
|
||||
$existing_var_type->addType(new Atomic\TIntRange(1, $assertion_value));
|
||||
}
|
||||
} elseif ($atomic_type instanceof TInt) {
|
||||
$existing_var_type->removeType($atomic_type->getKey());
|
||||
$existing_var_type->addType(new Atomic\TIntRange(null, $assertion_value));
|
||||
|
@ -1533,11 +1533,10 @@ class SimpleNegatedAssertionReconciler extends Reconciler
|
||||
}
|
||||
}*/
|
||||
} elseif ($atomic_type instanceof Atomic\TPositiveInt) {
|
||||
if ($assertion_value > 0) {
|
||||
//emit an issue here in the future about incompatible type
|
||||
}
|
||||
$existing_var_type->removeType($atomic_type->getKey());
|
||||
$existing_var_type->addType(new Atomic\TIntRange(null, $assertion_value));
|
||||
if ($assertion_value >= 1) {
|
||||
$existing_var_type->addType(new Atomic\TIntRange(1, $assertion_value));
|
||||
}
|
||||
} elseif ($atomic_type instanceof TInt) {
|
||||
$existing_var_type->removeType($atomic_type->getKey());
|
||||
$existing_var_type->addType(new Atomic\TIntRange(null, $assertion_value));
|
||||
@ -1578,11 +1577,10 @@ class SimpleNegatedAssertionReconciler extends Reconciler
|
||||
}
|
||||
}*/
|
||||
} elseif ($atomic_type instanceof Atomic\TPositiveInt) {
|
||||
if ($assertion_value > 0) {
|
||||
//emit an issue here in the future about incompatible type
|
||||
if ($assertion_value > 1) {
|
||||
$existing_var_type->removeType($atomic_type->getKey());
|
||||
$existing_var_type->addType(new Atomic\TIntRange($assertion_value, null));
|
||||
}
|
||||
$existing_var_type->removeType($atomic_type->getKey());
|
||||
$existing_var_type->addType(new Atomic\TIntRange($assertion_value, 1));
|
||||
} elseif ($atomic_type instanceof TInt) {
|
||||
$existing_var_type->removeType($atomic_type->getKey());
|
||||
$existing_var_type->addType(new Atomic\TIntRange($assertion_value, null));
|
||||
|
@ -644,6 +644,30 @@ class IntRangeTest extends TestCase
|
||||
}
|
||||
}',
|
||||
],
|
||||
'positiveIntToRangeWithInferior' => [
|
||||
'<?php
|
||||
/** @var positive-int $length */
|
||||
$length = 0;
|
||||
|
||||
if ($length < 8) {
|
||||
throw new \RuntimeException();
|
||||
}',
|
||||
'assertions' => [
|
||||
'$length===' => 'int<8, max>',
|
||||
],
|
||||
],
|
||||
'positiveIntToRangeWithSuperiorOrEqual' => [
|
||||
'<?php
|
||||
/** @var positive-int $length */
|
||||
$length = 0;
|
||||
|
||||
if ($length >= 8) {
|
||||
throw new \RuntimeException();
|
||||
}',
|
||||
'assertions' => [
|
||||
'$length===' => 'int<1, 7>',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user