fix contract-stronger for struct/dc with #:inv clauses

This commit is contained in:
Robby Findler 2014-05-03 21:53:58 -05:00
parent abd445839d
commit 974ee9df75
2 changed files with 34 additions and 0 deletions

View File

@ -205,6 +205,27 @@
[a number?]
[b number?]))
(,test #f
contract-stronger?
(struct/dc s
[a integer?]
[b integer?])
(struct/dc s
[a integer?]
[b integer?]
#:inv (a b) #f))
(,test #t
contract-stronger?
(struct/dc s
[a integer?]
[b integer?]
#:inv (a b) #f)
(struct/dc s
[a integer?]
[b integer?]))
(define (mk c)
(struct/dc s
[a (>=/c c)]

View File

@ -594,6 +594,14 @@
(define (struct/dc-stronger? this that)
(and (base-struct/dc? that)
(eq? (base-struct/dc-pred this) (base-struct/dc-pred that))
(let ([this-inv (get-invariant this)]
[that-inv (get-invariant that)])
(cond
[(not that-inv) #t]
[(not this-inv) #f]
[else
(procedure-closure-contents-eq? (invariant-dep-proc this-inv)
(invariant-dep-proc that-inv))]))
(for/and ([this-subcontract (in-list (base-struct/dc-subcontracts this))]
[that-subcontract (in-list (base-struct/dc-subcontracts that))])
(cond
@ -618,6 +626,11 @@
(dep-dep-proc that-subcontract)))]
[else #t]))))
(define (get-invariant sc)
(for/or ([sub (base-struct/dc-subcontracts sc)]
#:when (invariant? sub))
sub))
(define-struct base-struct/dc (subcontracts pred struct-name here name-info struct/c?))
(define-struct (struct/dc base-struct/dc) ()