From 89a06cfae6352f54794f3d589d7421f40e6fc036 Mon Sep 17 00:00:00 2001 From: Vincent St-Amour Date: Tue, 3 Nov 2015 16:02:05 -0600 Subject: [PATCH] Fix bitwise-and on negative numbers. Found using random testing. --- .../typed-racket/base-env/base-env-numeric.rkt | 12 ++++++------ typed-racket-test/unit-tests/typecheck-tests.rkt | 1 + 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/typed-racket-lib/typed-racket/base-env/base-env-numeric.rkt b/typed-racket-lib/typed-racket/base-env/base-env-numeric.rkt index f6b34c60..26f6326d 100644 --- a/typed-racket-lib/typed-racket/base-env/base-env-numeric.rkt +++ b/typed-racket-lib/typed-racket/base-env/base-env-numeric.rkt @@ -1377,16 +1377,16 @@ (-Int -Int . -> . -Int))] [bitwise-and - (let ([mix-with-int + (let ([mix-with-nat (lambda (t) (list (->* (list t) t t) ; closed - (->* (list -Int t) t t) ; brings result down - (->* (list t -Int) t t)))]) + (->* (list -Nat t) t t) ; brings result down + (->* (list t -Nat) t t)))]) (from-cases (-> -NegFixnum) ; no args -> -1 - (map mix-with-int (list -Zero -Byte -Index -NonNegFixnum)) + (map mix-with-nat (list -Zero -Byte -Index -NonNegFixnum)) ;; closed on negatives, but not closed if we mix with positives - (map varop-1+ (list -NegFixnum -NonPosFixnum)) - (map mix-with-int (list -Fixnum -Nat)) + (map varop-1+ (list -NegFixnum -NonPosFixnum -Fixnum)) + (map mix-with-nat (list -Nat)) (map varop-1+ (list -NegInt -NonPosInt)) (null -Int . ->* . -Int)))] [bitwise-ior diff --git a/typed-racket-test/unit-tests/typecheck-tests.rkt b/typed-racket-test/unit-tests/typecheck-tests.rkt index c608dbd8..55f224a4 100644 --- a/typed-racket-test/unit-tests/typecheck-tests.rkt +++ b/typed-racket-test/unit-tests/typecheck-tests.rkt @@ -454,6 +454,7 @@ (tc-e (expt (make-rectangular 3 -1.7976931348623157e+308) (flacos (real->double-flonum 59.316513f0))) (t:Un -Flonum -FloatComplex)) (tc-e (exact->inexact (ann 3 Number)) (t:Un -InexactReal -InexactComplex)) (tc-e (/ (round (exact-round -2.7393196f0)) (real->double-flonum (inexact->exact (real->single-flonum -0.0)))) -Real) + (tc-e (bitwise-and (exact-round 1.7976931348623157e+308) (exact-round -29)) -Int) (tc-e (exact->inexact 3) -PosFlonum) (tc-e (exact->inexact -3) -NegFlonum) (tc-e (real->double-flonum 0.0) -FlonumPosZero)