Skip to content

Commit 895e35e

Browse files
committed
contract: avoid leaving observable in a bad state after update contract error
The original implementation applied val-set to the result of applying update-proc to proc, which was too late. Instead, pass a proc' to update-proc that applies val-set to the updated value, ensuring that val-set is called before the box is mutated.
1 parent 1cf5409 commit 895e35e

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

gui-easy-lib/gui/easy/contract.rkt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,9 @@
4848
[(obs? o)
4949
(check-init-value (obs-peek o) neg-party)
5050
(impersonate-obs o
51-
#:set
52-
(lambda (_ v)
53-
(check-updated-value v neg-party)
54-
v))]
51+
#:set (lambda (_ v)
52+
(begin0 v
53+
(check-updated-value v neg-party))))]
5554
[else
5655
(raise-blame-error
5756
#:missing-party neg-party
@@ -83,6 +82,7 @@
8382
#rx"expected: \\(>=/c 5\\)"
8483
(λ ()
8584
(obs-update! o sub1)))
85+
(check-equal? (obs-peek o) 5)
8686
(check-exn
8787
#rx"promised: \\(>=/c 5\\)"
8888
(λ ()

gui-easy-lib/gui/easy/private/observable.rkt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,13 @@
100100
#f ; witness
101101
obs-update-value-box!
102102
(and val-set
103-
(λ (o update-proc) ;; noqa
103+
(λ (o update-proc) ; update-proc: (a -> b) -> b ;; noqa
104104
(do-impersonate-procedure
105-
update-proc
106-
(λ (proc)
107-
(values
108-
(λ (v) (val-set o v))
109-
proc)))))
105+
update-proc ; update-proc': (a -> b) -> c
106+
(λ (proc) ; proc: a -> b
107+
(λ (v) ; proc': a -> c
108+
; val-set: b -> c
109+
(val-set o (proc v)))))))
110110
set-obs-update-value-box!!
111111
#f))
112112

gui-easy-lib/info.rkt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#lang info
22

33
(define license 'BSD-3-Clause)
4-
(define version "0.19")
4+
(define version "0.19.1")
55
(define collection "racket")
66
(define deps
77
'("base"

0 commit comments

Comments
 (0)