From e9ac465ace8ea90955cb3460a583543e168be223 Mon Sep 17 00:00:00 2001 From: orklah Date: Sun, 23 Jan 2022 21:57:21 +0100 Subject: [PATCH] remove PositiveNumeric assertions --- .../Statements/Expression/AssertionFinder.php | 1 - .../Type/NegatedAssertionReconciler.php | 5 - .../Type/SimpleAssertionReconciler.php | 93 ------------------- .../Assertion/IsNotPositiveNumeric.php | 30 ------ .../Storage/Assertion/IsPositiveNumeric.php | 38 -------- 5 files changed, 167 deletions(-) delete mode 100644 src/Psalm/Storage/Assertion/IsNotPositiveNumeric.php delete mode 100644 src/Psalm/Storage/Assertion/IsPositiveNumeric.php diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/AssertionFinder.php b/src/Psalm/Internal/Analyzer/Statements/Expression/AssertionFinder.php index 60b7a5738d1..3c002791e68 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/AssertionFinder.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/AssertionFinder.php @@ -58,7 +58,6 @@ use Psalm\Storage\Assertion\IsNotIdentical; use Psalm\Storage\Assertion\IsNotLooselyEqual; use Psalm\Storage\Assertion\IsNotType; -use Psalm\Storage\Assertion\IsPositiveNumeric; use Psalm\Storage\Assertion\IsType; use Psalm\Storage\Assertion\NestedAssertions; use Psalm\Storage\Assertion\NonEmptyCountable; diff --git a/src/Psalm/Internal/Type/NegatedAssertionReconciler.php b/src/Psalm/Internal/Type/NegatedAssertionReconciler.php index 0092b093a6b..4d5036c617e 100644 --- a/src/Psalm/Internal/Type/NegatedAssertionReconciler.php +++ b/src/Psalm/Internal/Type/NegatedAssertionReconciler.php @@ -11,7 +11,6 @@ use Psalm\Storage\Assertion\IsClassNotEqual; use Psalm\Storage\Assertion\IsNotCountable; use Psalm\Storage\Assertion\IsNotIdentical; -use Psalm\Storage\Assertion\IsNotPositiveNumeric; use Psalm\Storage\Assertion\IsNotType; use Psalm\Type; use Psalm\Type\Atomic; @@ -87,10 +86,6 @@ public static function reconcile( ); } - if ($is_equality && $assertion instanceof IsNotPositiveNumeric) { - return $existing_var_type; - } - $existing_var_atomic_types = $existing_var_type->getAtomicTypes(); if ($assertion_type instanceof TFalse && isset($existing_var_atomic_types['bool'])) { diff --git a/src/Psalm/Internal/Type/SimpleAssertionReconciler.php b/src/Psalm/Internal/Type/SimpleAssertionReconciler.php index aaf7ce5e3c2..46472ec9a4d 100644 --- a/src/Psalm/Internal/Type/SimpleAssertionReconciler.php +++ b/src/Psalm/Internal/Type/SimpleAssertionReconciler.php @@ -22,7 +22,6 @@ use Psalm\Storage\Assertion\IsIsset; use Psalm\Storage\Assertion\IsLessThan; use Psalm\Storage\Assertion\IsLooselyEqual; -use Psalm\Storage\Assertion\IsPositiveNumeric; use Psalm\Storage\Assertion\IsType; use Psalm\Storage\Assertion\NonEmpty; use Psalm\Storage\Assertion\NonEmptyCountable; @@ -238,19 +237,6 @@ public static function reconcile( ); } - if ($assertion instanceof IsPositiveNumeric) { - return self::reconcilePositiveNumeric( - $assertion, - $existing_var_type, - $key, - $negated, - $code_location, - $suppressed_issues, - $failed_reconciliation, - $is_equality - ); - } - if ($assertion instanceof NonEmptyCountable) { return self::reconcileNonEmptyCountable( $assertion, @@ -725,85 +711,6 @@ private static function reconcileExactlyCountable( return $existing_var_type; } - /** - * @param string[] $suppressed_issues - * @param Reconciler::RECONCILIATION_* $failed_reconciliation - */ - private static function reconcilePositiveNumeric( - Assertion $assertion, - Union $existing_var_type, - ?string $key, - bool $negated, - ?CodeLocation $code_location, - array $suppressed_issues, - int &$failed_reconciliation, - bool $is_equality - ): Union { - $old_var_type_string = $existing_var_type->getId(); - - $did_remove_type = false; - - $positive_types = []; - - foreach ($existing_var_type->getAtomicTypes() as $atomic_type) { - if ($atomic_type instanceof TLiteralInt) { - if ($atomic_type->value < 1) { - $did_remove_type = true; - } else { - $positive_types[] = $atomic_type; - } - } elseif ($atomic_type instanceof TPositiveInt) { - $positive_types[] = $atomic_type; - } elseif ($atomic_type instanceof TIntRange) { - if (!$atomic_type->isPositive()) { - $did_remove_type = true; - } - $positive_types[] = new TIntRange( - $atomic_type->min_bound === null ? 1 : max(1, $atomic_type->min_bound), - $atomic_type->max_bound === null ? null : max(1, $atomic_type->max_bound) - ); - } elseif (get_class($atomic_type) === TInt::class) { - $positive_types[] = new TPositiveInt(); - $did_remove_type = true; - } else { - // for now allow this check everywhere else - if (!$atomic_type instanceof TNull - && !$atomic_type instanceof TFalse - ) { - $positive_types[] = $atomic_type; - } - - $did_remove_type = true; - } - } - - if (!$is_equality - && !$existing_var_type->hasMixed() - && (!$did_remove_type || !$positive_types) - ) { - if ($key && $code_location) { - self::triggerIssueForImpossible( - $existing_var_type, - $old_var_type_string, - $key, - $assertion, - !$did_remove_type, - $negated, - $code_location, - $suppressed_issues - ); - } - } - - if ($positive_types) { - return new Union($positive_types); - } - - $failed_reconciliation = Reconciler::RECONCILIATION_EMPTY; - - return Type::getNever(); - } - /** * @param string[] $suppressed_issues * @param Reconciler::RECONCILIATION_* $failed_reconciliation diff --git a/src/Psalm/Storage/Assertion/IsNotPositiveNumeric.php b/src/Psalm/Storage/Assertion/IsNotPositiveNumeric.php deleted file mode 100644 index 02016b095e1..00000000000 --- a/src/Psalm/Storage/Assertion/IsNotPositiveNumeric.php +++ /dev/null @@ -1,30 +0,0 @@ -is_negatable = $is_negatable; - } - - /** @psalm-mutation-free */ - public function getNegation(): Assertion - { - return $this->is_negatable ? new IsNotPositiveNumeric() : new Any(); - } - - /** @psalm-mutation-free */ - public function hasEquality(): bool - { - return !$this->is_negatable; - } - - public function __toString(): string - { - return (!$this->is_negatable ? '=' : '') . 'positive-numeric'; - } - - /** @psalm-mutation-free */ - public function isNegationOf(Assertion $assertion): bool - { - return $assertion instanceof IsNotPositiveNumeric; - } -}