From cc642c3382f6233583209e956d8100bdfedd6c59 Mon Sep 17 00:00:00 2001 From: Robby Findler Date: Fri, 23 Jan 2015 21:55:25 -0600 Subject: [PATCH] change +nan.0 and +nan.f, when viewed as contracts, to be equal?-based contracts instead of = based contracts. Before this change, the contract (or/c 1 2 +nan.0) was the same contract as (or/c 1 2), because +nan.0 was the same contract as the predicate (lambda (x) (= x +nan.0)), which is the same as (lambda (x) #f). Now, +nan.0 and +nan.f are the only numbers that are treated as equal?-based contracts, but this means that (or/c 1 2 +nan.0) actually accepts +nan.0. --- pkgs/racket-doc/scribblings/reference/contracts.scrbl | 9 +++++++-- pkgs/racket-test/tests/racket/contract-rand-test.rkt | 1 + .../racket-test/tests/racket/contract/flat-contracts.rkt | 2 ++ racket/collects/racket/contract/private/guts.rkt | 2 +- racket/collects/racket/contract/private/opt.rkt | 2 +- 5 files changed, 12 insertions(+), 4 deletions(-) diff --git a/pkgs/racket-doc/scribblings/reference/contracts.scrbl b/pkgs/racket-doc/scribblings/reference/contracts.scrbl index bb2025a33b..d4c6ad9dab 100644 --- a/pkgs/racket-doc/scribblings/reference/contracts.scrbl +++ b/pkgs/racket-doc/scribblings/reference/contracts.scrbl @@ -56,10 +56,12 @@ ordinary Racket values that double as contracts, including @racket[null], which are treated as contracts that recognize themselves, using @racket[eq?], } -@item{@tech{strings} and @tech{byte strings}, which are treated as contracts +@item{@tech{strings}, @tech{byte strings}, @racket[+nan.0], and + @racket[+nan.f], which are treated as contracts that recognize themselves using @racket[equal?], } -@item{@tech{numbers}, which are treated as contracts +@item{@tech{numbers} (except @racket[+nan.0] and + @racket[+nan.f]), which are treated as contracts that recognize themselves using @racket[=],} @item{@tech{regular expressions}, which are treated as contracts @@ -114,6 +116,9 @@ For more about this hierarchy, see @tech{chaperones} and a research paper on chaperones, impersonators, and how they can be used to implement contracts @cite{Strickland12}. +@history[#:changed "6.1.1.8" @list{Changed @racket[+nan.0] and @racket[+nan.f] to + be @racket[equal?]-based contracts.}] + @local-table-of-contents[] @; ---------------------------------------- diff --git a/pkgs/racket-test/tests/racket/contract-rand-test.rkt b/pkgs/racket-test/tests/racket/contract-rand-test.rkt index 02a9c20937..dbfe9e104f 100644 --- a/pkgs/racket-test/tests/racket/contract-rand-test.rkt +++ b/pkgs/racket-test/tests/racket/contract-rand-test.rkt @@ -27,6 +27,7 @@ ;; test =, eq?, and equal? contract random generators (check-not-exn (λ () (test-contract-generation 0))) +(check-not-exn (λ () (test-contract-generation +nan.0))) (check-not-exn (λ () (test-contract-generation 'x))) (check-not-exn (λ () (test-contract-generation "x"))) diff --git a/pkgs/racket-test/tests/racket/contract/flat-contracts.rkt b/pkgs/racket-test/tests/racket/contract/flat-contracts.rkt index 5e4cfcaf9a..fb26c19300 100644 --- a/pkgs/racket-test/tests/racket/contract/flat-contracts.rkt +++ b/pkgs/racket-test/tests/racket/contract/flat-contracts.rkt @@ -58,6 +58,8 @@ (test-flat-contract "x" "x" 'x) (test-flat-contract 1 1 2) (test-flat-contract #e1 #i1.0 'x) + (test-flat-contract +nan.0 +nan.0 +nan.f) + (test-flat-contract +nan.f +nan.f +nan.0) (test-flat-contract #rx".x." "axq" "x") (test-flat-contract #rx#".x." #"axq" #"x") (test-flat-contract #rx".x." #"axq" #"x") diff --git a/racket/collects/racket/contract/private/guts.rkt b/racket/collects/racket/contract/private/guts.rkt index 0e310c3c77..be8228ec1b 100644 --- a/racket/collects/racket/contract/private/guts.rkt +++ b/racket/collects/racket/contract/private/guts.rkt @@ -251,7 +251,7 @@ `',x x) name))] - [(or (bytes? x) (string? x)) + [(or (bytes? x) (string? x) (equal? +nan.0 x) (equal? +nan.f x)) (make-equal-contract x (if (name-default? name) x name))] [(number? x) (make-=-contract x (if (name-default? name) x name))] diff --git a/racket/collects/racket/contract/private/opt.rkt b/racket/collects/racket/contract/private/opt.rkt index b24c6d06b4..2201eb1624 100644 --- a/racket/collects/racket/contract/private/opt.rkt +++ b/racket/collects/racket/contract/private/opt.rkt @@ -85,7 +85,7 @@ [(or (boolean? konst) (char? konst) (null? konst)) (values #`(eq? #,konst #,v) "eq?")] - [(or (string? konst) (bytes? konst)) + [(or (string? konst) (bytes? konst) (equal? konst +nan.0) (equal? konst +nan.f)) (values #`(equal? #,konst #,v) "equal?")] [(number? konst)