From 0a81627eca8233edca95368938c739a9d268407f Mon Sep 17 00:00:00 2001 From: Eric Dobson Date: Wed, 26 Feb 2014 20:33:18 -0800 Subject: [PATCH] Fix type of - to not be wrong on negative fixnums Rolling this forward because the math library is no longer dependent on the broken behavior. Also nothing in the main repo seems to depend on this. --- .../typed-racket/base-env/base-env-numeric.rkt | 9 ++++++++- .../tests/typed-racket/unit-tests/typecheck-tests.rkt | 3 ++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/base-env/base-env-numeric.rkt b/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/base-env/base-env-numeric.rkt index 71a72f7874..6ee8812623 100644 --- a/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/base-env/base-env-numeric.rkt +++ b/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/base-env/base-env-numeric.rkt @@ -656,6 +656,13 @@ (-> -Zero neg pos) (-> -Zero non-pos non-neg))) + ;; Used because (- min-fixnum) > max-fixnum + (define (half-negation-pattern pos neg non-neg non-pos) + (list (-> pos neg) + (-> non-neg non-pos) + (-> -Zero pos neg) + (-> -Zero non-neg non-pos))) + (define abs-cases ; used both for abs and magnitude (list (map unop (list -Zero -One -PosByte -Byte -PosIndex -Index -PosFixnum -NonNegFixnum)) @@ -1181,7 +1188,7 @@ [- (from-cases (binop -Zero) - (negation-pattern -PosFixnum -NegFixnum -NonNegFixnum -NonPosFixnum) + (half-negation-pattern -PosFixnum -NegFixnum -NonNegFixnum -NonPosFixnum) (negation-pattern -PosInt -NegInt -Nat -NonPosInt) (negation-pattern -PosRat -NegRat -NonNegRat -NonPosRat) (negation-pattern -PosFlonum -NegFlonum -NonNegFlonum -NonPosFlonum) diff --git a/pkgs/typed-racket-pkgs/typed-racket-test/tests/typed-racket/unit-tests/typecheck-tests.rkt b/pkgs/typed-racket-pkgs/typed-racket-test/tests/typed-racket/unit-tests/typecheck-tests.rkt index 382b74fd1d..517e40dac9 100644 --- a/pkgs/typed-racket-pkgs/typed-racket-test/tests/typed-racket/unit-tests/typecheck-tests.rkt +++ b/pkgs/typed-racket-pkgs/typed-racket-test/tests/typed-racket/unit-tests/typecheck-tests.rkt @@ -242,7 +242,8 @@ (tc-e (+ 3 4) -PosIndex) (tc-e (- 1) -NegFixnum) (tc-e (- 1073741823) -NegFixnum) - (tc-e (- -4) -PosFixnum) + (tc-e (- -4) -PosInt) + (tc-e (- (ann -5 Nonpositive-Fixnum)) -Nat) (tc-e/t 1152921504606846975 -PosInt) (tc-e/t -1152921504606846975 -NegInt) (tc-e (- 3253463567262345623) -NegInt)