improve contract-stronger for instanceof/c
This commit is contained in:
parent
9ea9d0eaf8
commit
9681032783
|
@ -2,7 +2,8 @@
|
|||
(require "test-util.rkt")
|
||||
|
||||
(parameterize ([current-contract-namespace
|
||||
(make-basic-contract-namespace 'racket/contract)])
|
||||
(make-basic-contract-namespace 'racket/contract
|
||||
'racket/class)])
|
||||
|
||||
(contract-eval '(define-contract-struct couple (hd tl)))
|
||||
(contract-eval '(define-contract-struct triple (a b c)))
|
||||
|
@ -149,6 +150,10 @@
|
|||
(ctest #t contract-stronger? 'x symbol?)
|
||||
(ctest #f contract-stronger? symbol? 'x)
|
||||
|
||||
(contract-eval
|
||||
`(let ([c (class/c (m (-> any/c integer?)))])
|
||||
(,test #t contract-stronger? (instanceof/c c) (instanceof/c c))))
|
||||
|
||||
;; chances are, this predicate will accept "x", but
|
||||
;; we don't want to consider it stronger, since it
|
||||
;; will not always accept "x".
|
||||
|
|
|
@ -825,10 +825,12 @@
|
|||
absents absent-fields
|
||||
internal opaque? name)
|
||||
#:omit-define-syntaxes
|
||||
#:property prop:custom-write custom-write-property-proc
|
||||
#:property prop:contract
|
||||
(build-contract-property
|
||||
#:projection class/c-proj
|
||||
#:name build-class/c-name
|
||||
#:stronger (λ (this that) (equal? this that))
|
||||
#:first-order
|
||||
(λ (ctc)
|
||||
(λ (cls)
|
||||
|
@ -1118,6 +1120,7 @@
|
|||
(λ args (ret #f))))))
|
||||
|
||||
(define-struct base-object/c (methods method-contracts fields field-contracts)
|
||||
#:property prop:custom-write custom-write-property-proc
|
||||
#:property prop:contract
|
||||
(build-contract-property
|
||||
#:projection object/c-proj
|
||||
|
@ -1187,14 +1190,22 @@
|
|||
(and (object? val)
|
||||
(contract-first-order-passes? cls-ctc (object-ref val))))))
|
||||
|
||||
|
||||
(define (instanceof/c-stronger this that)
|
||||
(and (base-instanceof/c? that)
|
||||
(contract-stronger? (base-instanceof/c-class-ctc this)
|
||||
(base-instanceof/c-class-ctc that))))
|
||||
|
||||
(define-struct base-instanceof/c (class-ctc)
|
||||
#:property prop:custom-write custom-write-property-proc
|
||||
#:property prop:contract
|
||||
(build-contract-property
|
||||
#:projection instanceof/c-proj
|
||||
#:name
|
||||
(λ (ctc)
|
||||
(build-compound-type-name 'instanceof/c (base-instanceof/c-class-ctc ctc)))
|
||||
#:first-order instanceof/c-first-order))
|
||||
#:first-order instanceof/c-first-order
|
||||
#:stronger instanceof/c-stronger))
|
||||
|
||||
(define (instanceof/c cctc)
|
||||
(let ([ctc (coerce-contract 'instanceof/c cctc)])
|
||||
|
|
Loading…
Reference in New Issue
Block a user