Skip to content

Commit 01fb28f

Browse files
committed
fix cons/c for combinators that insist on projections for subcontracts
(instead of working with val-first projections)
1 parent a0485cb commit 01fb28f

File tree

2 files changed

+42
-5
lines changed
  • pkgs/racket-pkgs/racket-test/tests/racket/contract
  • racket/collects/racket/contract/private

2 files changed

+42
-5
lines changed

pkgs/racket-pkgs/racket-test/tests/racket/contract/box.rkt

+22-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,25 @@
55
'(let ([v (chaperone-box (box-immutable 1)
66
(λ (box v) v)
77
(λ (box v) v))])
8-
(contract (box/c any/c) v 'pos 'neg))))
8+
(contract (box/c any/c) v 'pos 'neg)))
9+
10+
(test/pos-blame
11+
'box/c1
12+
'(contract (box/c any/c) #f 'pos 'neg))
13+
14+
(test/pos-blame
15+
'box/c2
16+
'(unbox (contract (box/c integer?) (box #f) 'pos 'neg)))
17+
18+
(test/pos-blame
19+
'box/c3
20+
'(contract (box/c integer?) (box-immutable #f) 'pos 'neg))
21+
22+
(test/neg-blame
23+
'box/c-with-cons/c-inside
24+
'(let ([f
25+
(contract (box/c (cons/c (-> boolean? boolean?) '()))
26+
(box (list values))
27+
'pos
28+
'neg)])
29+
((car (unbox f)) 3))))

racket/collects/racket/contract/private/misc.rkt

+20-4
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@
534534
(define (blame-add-cdr-context blame) (blame-add-context blame "the cdr of"))
535535

536536

537-
(define ((val-first-ho-check combine) ctc)
537+
(define ((cons/c-val-first-ho-check combine) ctc)
538538
(define ctc-car (the-cons/c-hd-ctc ctc))
539539
(define ctc-cdr (the-cons/c-tl-ctc ctc))
540540
(define car-val-first-proj (get/build-val-first-projection ctc-car))
@@ -550,6 +550,19 @@
550550
((car-p (car v)) neg-party)
551551
((cdr-p (cdr v)) neg-party))))))
552552

553+
(define ((cons/c-ho-check combine) ctc)
554+
(define ctc-car (the-cons/c-hd-ctc ctc))
555+
(define ctc-cdr (the-cons/c-tl-ctc ctc))
556+
(define car-proj (contract-projection ctc-car))
557+
(define cdr-proj (contract-projection ctc-cdr))
558+
(λ (blame)
559+
(let ([car-p (car-proj (blame-add-car-context blame))]
560+
[cdr-p (cdr-proj (blame-add-cdr-context blame))])
561+
(λ (v)
562+
(unless (pair? v)
563+
(raise-not-cons-blame-error blame v))
564+
(combine v (car-p (car v)) (cdr-p (cdr v)))))))
565+
553566
(define (cons/c-first-order ctc)
554567
(define ctc-car (the-cons/c-hd-ctc ctc))
555568
(define ctc-cdr (the-cons/c-tl-ctc ctc))
@@ -585,7 +598,8 @@
585598
#:property prop:custom-write custom-write-property-proc
586599
#:property prop:flat-contract
587600
(build-flat-contract-property
588-
#:val-first-projection (val-first-ho-check (λ (v a d) v))
601+
#:val-first-projection (cons/c-val-first-ho-check (λ (v a d) v))
602+
#:projection (cons/c-ho-check (λ (v a d) v))
589603
#:name cons/c-name
590604
#:first-order cons/c-first-order
591605
#:stronger cons/c-stronger?
@@ -595,7 +609,8 @@
595609
#:property prop:chaperone-contract
596610
(parameterize ([skip-projection-wrapper? #t])
597611
(build-chaperone-contract-property
598-
#:val-first-projection (val-first-ho-check (λ (v a d) (cons a d)))
612+
#:val-first-projection (cons/c-val-first-ho-check (λ (v a d) (cons a d)))
613+
#:projection (cons/c-ho-check (λ (v a d) (cons a d)))
599614
#:name cons/c-name
600615
#:first-order cons/c-first-order
601616
#:stronger cons/c-stronger?
@@ -604,7 +619,8 @@
604619
#:property prop:custom-write custom-write-property-proc
605620
#:property prop:contract
606621
(build-contract-property
607-
#:val-first-projection (val-first-ho-check (λ (v a d) (cons a d)))
622+
#:val-first-projection (cons/c-val-first-ho-check (λ (v a d) (cons a d)))
623+
#:projection (cons/c-ho-check (λ (v a d) (cons a d)))
608624
#:name cons/c-name
609625
#:first-order cons/c-first-order
610626
#:stronger cons/c-stronger?

0 commit comments

Comments
 (0)