diff --git a/pkgs/racket-test/tests/racket/contract/stronger.rkt b/pkgs/racket-test/tests/racket/contract/stronger.rkt index 9783e91149..dc30bfc608 100644 --- a/pkgs/racket-test/tests/racket/contract/stronger.rkt +++ b/pkgs/racket-test/tests/racket/contract/stronger.rkt @@ -10,6 +10,7 @@ (contract-eval '(define-contract-struct triple (a b c))) (ctest #t contract-stronger? any/c any/c) + (ctest #t contract-stronger? integer? any/c) (ctest #t contract-stronger? (integer-in 0 4) (integer-in 0 4)) (ctest #t contract-stronger? (integer-in 1 3) (integer-in 0 4)) (ctest #f contract-stronger? (integer-in 0 4) (integer-in 1 3)) @@ -74,6 +75,8 @@ (ctest #t contract-stronger? (-> #:x (>=/c 3) (>=/c 3)) (-> #:x (>=/c 3) (>=/c 2))) (ctest #t contract-stronger? (-> any/c any/c any) (-> any/c any/c any)) (ctest #f contract-stronger? (-> any/c any/c any/c any) (-> any/c any/c any)) + (ctest #t contract-stronger? (-> (-> any/c) integer?) (-> (-> any/c) any/c)) + (ctest #f contract-stronger? (-> (-> any/c) any/c) (-> (-> any/c) integer?)) (let ([c (contract-eval '(->* () () any))]) (test #t (contract-eval 'contract-stronger?) c c)) @@ -89,8 +92,8 @@ (->* () integer? #:post (zero? (random 10))) (->* () integer? #:post (zero? (random 10)))) - (ctest #t contract-stronger? (or/c null? any/c) (or/c null? any/c)) - (ctest #f contract-stronger? (or/c null? any/c) (or/c boolean? any/c)) + (ctest #t contract-stronger? (or/c null? #f) (or/c null? #f)) + (ctest #f contract-stronger? (or/c null? #f) (or/c boolean? #f)) (ctest #t contract-stronger? (or/c null? boolean?) (or/c null? boolean?)) (ctest #t contract-stronger? (or/c null? boolean?) (or/c boolean? null?)) (ctest #t contract-stronger? @@ -111,8 +114,8 @@ (ctest #f contract-stronger? (-> (or/c #f number?)) (-> number?)) (ctest #f contract-stronger? (-> number? any/c) (-> (or/c #f number?) any/c)) - (ctest #t contract-stronger? (first-or/c null? any/c) (first-or/c null? any/c)) - (ctest #f contract-stronger? (first-or/c null? any/c) (first-or/c boolean? any/c)) + (ctest #t contract-stronger? (first-or/c null? #f) (first-or/c null? #f)) + (ctest #f contract-stronger? (first-or/c null? #f) (first-or/c boolean? #f)) (ctest #t contract-stronger? (first-or/c null? boolean?) (first-or/c null? boolean?)) (ctest #t contract-stronger? (first-or/c null? boolean?) (first-or/c boolean? null?)) (ctest #t contract-stronger? @@ -133,13 +136,13 @@ (ctest #f contract-stronger? (-> (first-or/c #f number?)) (-> number?)) (ctest #f contract-stronger? (-> number? any/c) (-> (first-or/c #f number?) any/c)) - (ctest #t contract-stronger? (first-or/c null? any/c) (or/c null? any/c)) - (ctest #f contract-stronger? (first-or/c null? any/c) (or/c boolean? any/c)) + (ctest #t contract-stronger? (first-or/c null? #f) (or/c null? #f)) + (ctest #f contract-stronger? (first-or/c null? #f) (or/c boolean? #f)) (ctest #t contract-stronger? (first-or/c null? boolean?) (or/c null? boolean?)) (ctest #t contract-stronger? (first-or/c null? boolean?) (or/c boolean? null?)) - (ctest #t contract-stronger? (or/c null? any/c) (first-or/c null? any/c)) - (ctest #f contract-stronger? (or/c null? any/c) (first-or/c boolean? any/c)) + (ctest #t contract-stronger? (or/c null? #f) (first-or/c null? #f)) + (ctest #f contract-stronger? (or/c null? #f) (first-or/c boolean? #f)) (ctest #t contract-stronger? (or/c null? boolean?) (first-or/c null? boolean?)) (ctest #t contract-stronger? (or/c null? boolean?) (first-or/c boolean? null?)) @@ -176,7 +179,7 @@ (or/c (-> string?) (-> integer? integer?)) (or/c (-> string?) (-> any/c integer?))) (ctest #f contract-stronger? - (or/c (-> string?) (-> any/c integer?)) + (or/c (-> string?) (-> #f integer?)) (or/c (-> string?) (-> integer? integer?))) (ctest #t contract-stronger? (or/c (-> string?) (-> integer? integer?) integer? boolean?) diff --git a/racket/collects/racket/contract/private/misc.rkt b/racket/collects/racket/contract/private/misc.rkt index 6025b72e96..7a2dbe399e 100644 --- a/racket/collects/racket/contract/private/misc.rkt +++ b/racket/collects/racket/contract/private/misc.rkt @@ -1447,6 +1447,7 @@ (define-struct any/c () #:property prop:custom-write custom-write-property-proc #:omit-define-syntaxes + #:property prop:any/c #f #:property prop:flat-contract (build-flat-contract-property #:late-neg-projection (λ (ctc) any/c-blame->neg-party-fn) diff --git a/racket/collects/racket/contract/private/prop.rkt b/racket/collects/racket/contract/private/prop.rkt index 9e95b1ce5d..4c51a8c21b 100644 --- a/racket/collects/racket/contract/private/prop.rkt +++ b/racket/collects/racket/contract/private/prop.rkt @@ -52,6 +52,8 @@ prop:arrow-contract-get-info (struct-out arrow-contract-info) + prop:any/c prop:any/c? + build-context) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -124,6 +126,7 @@ [(stronger? a b) ;; optimistically try skip some of the more complex work below #t] + [(and (flat-contract-struct? a) (prop:any/c? b)) #t] ;; is the flat-check needed here? [(let ([th (trail)]) (and th (for/or ([(a2 bs-h) (in-hash th)]) @@ -531,6 +534,11 @@ prop:recursive-contract-unroll) (make-struct-type-property 'prop:recursive-contract)) +;; this property's value isn't looked at; it is just a signal +;; that the contract accepts any value +(define-values (prop:any/c prop:any/c? prop:get-any/c) + (make-struct-type-property 'prop:any/c)) + ;; get-info : (-> ctc arrow-contract-info?) (define-values (prop:arrow-contract prop:arrow-contract? prop:arrow-contract-get-info) (make-struct-type-property 'prop:arrow-contract))