fix first-order test for struct/dc contracts
closes PR 13090
This commit is contained in:
parent
c16b696272
commit
e6a25f65ca
|
@ -128,6 +128,25 @@
|
||||||
(list (dep-type subcontract)))
|
(list (dep-type subcontract)))
|
||||||
...]]))))
|
...]]))))
|
||||||
|
|
||||||
|
(define (struct/dc-flat-first-order ctc)
|
||||||
|
(define struct-pred? (base-struct/dc-pred ctc))
|
||||||
|
(λ (v)
|
||||||
|
(and (struct-pred? v)
|
||||||
|
(let loop ([subcs (base-struct/dc-subcontracts ctc)]
|
||||||
|
[args '()])
|
||||||
|
(cond
|
||||||
|
[(null? subcs) #t]
|
||||||
|
[else
|
||||||
|
(define subc (car subcs))
|
||||||
|
(define val ((subcontract-ref subc) v))
|
||||||
|
(cond
|
||||||
|
[(indep? subc)
|
||||||
|
(and ((flat-contract-predicate (indep-ctc subc)) val)
|
||||||
|
(loop (cdr subcs) (cons val args)))]
|
||||||
|
[else
|
||||||
|
(and ((flat-contract-predicate (apply (dep-dep-proc subc) args)) val)
|
||||||
|
(loop (cdr subcs) (cons val args)))])])))))
|
||||||
|
|
||||||
(define (struct/dc-first-order ctc)
|
(define (struct/dc-first-order ctc)
|
||||||
(base-struct/dc-pred ctc))
|
(base-struct/dc-pred ctc))
|
||||||
|
|
||||||
|
@ -426,7 +445,7 @@
|
||||||
(parameterize ([skip-projection-wrapper? #t])
|
(parameterize ([skip-projection-wrapper? #t])
|
||||||
(build-flat-contract-property
|
(build-flat-contract-property
|
||||||
#:name struct/dc-name
|
#:name struct/dc-name
|
||||||
#:first-order struct/dc-first-order
|
#:first-order struct/dc-flat-first-order
|
||||||
#:projection struct/dc-proj
|
#:projection struct/dc-proj
|
||||||
#:stronger struct/dc-stronger?)))
|
#:stronger struct/dc-stronger?)))
|
||||||
|
|
||||||
|
@ -456,15 +475,14 @@
|
||||||
(cond
|
(cond
|
||||||
[(indep? subcontract) (impersonator-contract? (indep-ctc subcontract))]
|
[(indep? subcontract) (impersonator-contract? (indep-ctc subcontract))]
|
||||||
[(dep? subcontract) (eq? '#:impersonator (dep-type subcontract))]))
|
[(dep? subcontract) (eq? '#:impersonator (dep-type subcontract))]))
|
||||||
((cond
|
(cond
|
||||||
[(and (andmap flat-subcontract? subcontracts)
|
[(and (andmap flat-subcontract? subcontracts)
|
||||||
(not (ormap subcontract-mutable-field? subcontracts)))
|
(not (ormap subcontract-mutable-field? subcontracts)))
|
||||||
make-flat-struct/dc]
|
(make-flat-struct/dc subcontracts pred struct-name here name-info struct/c?)]
|
||||||
[(ormap impersonator-subcontract? subcontracts)
|
[(ormap impersonator-subcontract? subcontracts)
|
||||||
make-impersonator-struct/dc]
|
(make-impersonator-struct/dc subcontracts pred struct-name here name-info struct/c?)]
|
||||||
[else
|
[else
|
||||||
make-struct/dc])
|
(make-struct/dc subcontracts pred struct-name here name-info struct/c?)]))
|
||||||
subcontracts pred struct-name here name-info struct/c?))
|
|
||||||
|
|
||||||
|
|
||||||
(define-for-syntax (get-struct-info id stx)
|
(define-for-syntax (get-struct-info id stx)
|
||||||
|
|
|
@ -9468,6 +9468,14 @@
|
||||||
'neg)))
|
'neg)))
|
||||||
22)
|
22)
|
||||||
|
|
||||||
|
(test/spec-passed/result
|
||||||
|
'struct/c16
|
||||||
|
'(let ()
|
||||||
|
(struct doll (contents))
|
||||||
|
(list ((flat-contract-predicate (struct/c doll 'center)) (doll 'center))
|
||||||
|
((flat-contract-predicate (struct/c doll 'center)) (doll 'not-center-center))))
|
||||||
|
'(#t #f))
|
||||||
|
|
||||||
|
|
||||||
;
|
;
|
||||||
;
|
;
|
||||||
|
@ -10227,6 +10235,34 @@
|
||||||
'neg)))
|
'neg)))
|
||||||
#\a)
|
#\a)
|
||||||
|
|
||||||
|
(test/spec-passed/result
|
||||||
|
'struct/dc-pred1
|
||||||
|
'(let ()
|
||||||
|
(struct s (a b))
|
||||||
|
(define p? (flat-contract-predicate (struct/dc s [a number?] [b (a) #:flat (<=/c a)])))
|
||||||
|
(list (p? (s 2 1))
|
||||||
|
(p? (s 1 2))))
|
||||||
|
'(#t #f))
|
||||||
|
|
||||||
|
(test/spec-passed/result
|
||||||
|
'struct/dc-pred2
|
||||||
|
'(let ()
|
||||||
|
(struct s (a b c))
|
||||||
|
(define p? (flat-contract-predicate (struct/dc s
|
||||||
|
[a number?]
|
||||||
|
[b boolean?]
|
||||||
|
[c (a b)
|
||||||
|
#:flat
|
||||||
|
(if (and (= a 1) b)
|
||||||
|
any/c
|
||||||
|
none/c)])))
|
||||||
|
|
||||||
|
(list (p? (s 1 #t 'whatever))
|
||||||
|
(p? (s 11 #f 'whatver))))
|
||||||
|
'(#t #f))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
(contract-error-test
|
(contract-error-test
|
||||||
'struct/dc-imp-nondep-runtime-error
|
'struct/dc-imp-nondep-runtime-error
|
||||||
#'(let ()
|
#'(let ()
|
||||||
|
@ -10367,6 +10403,20 @@
|
||||||
'(letrec ([ctc (or/c number? (hash/c (recursive-contract ctc #:chaperone) number?))])
|
'(letrec ([ctc (or/c number? (hash/c (recursive-contract ctc #:chaperone) number?))])
|
||||||
(make-hash (list (cons (make-hash (list (cons 3 4))) 5)))))
|
(make-hash (list (cons (make-hash (list (cons 3 4))) 5)))))
|
||||||
|
|
||||||
|
(test/pos-blame
|
||||||
|
'recursive-contract10
|
||||||
|
'(let ()
|
||||||
|
(struct doll (contents))
|
||||||
|
(letrec ([doll-ctc (recursive-contract (or/c 'center (struct/c doll doll-ctc)) #:flat)])
|
||||||
|
(contract doll-ctc (doll 3) 'pos 'neg))))
|
||||||
|
|
||||||
|
(test/pos-blame
|
||||||
|
'recursive-contract11
|
||||||
|
'(let ()
|
||||||
|
(struct doll (contents))
|
||||||
|
(letrec ([doll-ctc2 (or/c 'center (struct/c doll (recursive-contract doll-ctc2 #:flat)))])
|
||||||
|
(contract doll-ctc2 (doll 4) 'pos 'neg))))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
;
|
;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user