From 1fe5994bcb8b58012dbba0a5f7d03138c293286f Mon Sep 17 00:00:00 2001 From: Andrea Corallo Date: Wed, 17 Feb 2021 21:45:37 +0100 Subject: [PATCH] Fix inverted logic in constraint comparison (bug#46540) * lisp/emacs-lisp/comp-cstr.el (comp-cstr->, comp-cstr->=) (comp-cstr-<, comp-cstr-<=): Fix inverted logic. * test/src/comp-tests.el (comp-tests-type-spec-tests): Add three integer constrain tests. --- lisp/emacs-lisp/comp-cstr.el | 8 ++++---- test/src/comp-tests.el | 29 ++++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/lisp/emacs-lisp/comp-cstr.el b/lisp/emacs-lisp/comp-cstr.el index 1afb928e10c..3c00b68d0f6 100644 --- a/lisp/emacs-lisp/comp-cstr.el +++ b/lisp/emacs-lisp/comp-cstr.el @@ -791,7 +791,7 @@ SRC can be either a comp-cstr or an integer." (if (integerp src) `((,(1+ src) . +)) (when-let* ((range (range src)) - (low (comp-cstr-greatest-in-range range)) + (low (comp-cstr-smallest-in-range range)) (okay (integerp low))) `((,(1+ low) . +)))))) (comp-cstr-set-cmp-range dst old-dst ext-range)))) @@ -804,7 +804,7 @@ SRC can be either a comp-cstr or an integer." (if (integerp src) `((,src . +)) (when-let* ((range (range src)) - (low (comp-cstr-greatest-in-range range)) + (low (comp-cstr-smallest-in-range range)) (okay (integerp low))) `((,low . +)))))) (comp-cstr-set-cmp-range dst old-dst ext-range)))) @@ -817,7 +817,7 @@ SRC can be either a comp-cstr or an integer." (if (integerp src) `((- . ,(1- src))) (when-let* ((range (range src)) - (low (comp-cstr-smallest-in-range range)) + (low (comp-cstr-greatest-in-range range)) (okay (integerp low))) `((- . ,(1- low))))))) (comp-cstr-set-cmp-range dst old-dst ext-range)))) @@ -830,7 +830,7 @@ SRC can be either a comp-cstr or an integer." (if (integerp src) `((- . ,src)) (when-let* ((range (range src)) - (low (comp-cstr-smallest-in-range range)) + (low (comp-cstr-greatest-in-range range)) (okay (integerp low))) `((- . ,low)))))) (comp-cstr-set-cmp-range dst old-dst ext-range)))) diff --git a/test/src/comp-tests.el b/test/src/comp-tests.el index c0325a8d5df..08c18894419 100644 --- a/test/src/comp-tests.el +++ b/test/src/comp-tests.el @@ -1211,7 +1211,34 @@ Return a list of results." (= x 3)) (error "Not foo or 3")) x) - (or (member foo) (integer 3 3))))) + (or (member foo) (integer 3 3))) + + ;;58 + ((defun comp-tests-ret-type-spec-f (x y) + (if (and (natnump x) + (natnump y) + (<= x y)) + x + (error ""))) + (integer 0 *)) + + ;; 59 + ((defun comp-tests-ret-type-spec-f (x y) + (if (and (>= x 3) + (<= y 10) + (<= x y)) + x + (error ""))) + (or float (integer 3 10))) + + ;; 60 + ((defun comp-tests-ret-type-spec-f (x y) + (if (and (<= x 10) + (>= y 3) + (>= x y)) + x + (error ""))) + (or float (integer 3 10))))) (defun comp-tests-define-type-spec-test (number x) `(comp-deftest ,(intern (format "ret-type-spec-%d" number)) () -- 2.39.5