fixed struct field updates
This commit is contained in:
parent
e922807837
commit
e7d61bd982
|
@ -46,12 +46,16 @@
|
|||
;; a polymorphic field. Because subtyping is nominal and accessor
|
||||
;; functions do not reflect this, this behavior is unobservable
|
||||
;; except when an a variable aliases the field in a let binding
|
||||
(build-type make-Struct nm par
|
||||
(list-update flds idx (match-lambda
|
||||
[(fld: e acc-id #f)
|
||||
(make-fld (update e ft pos? rst) acc-id #f)]
|
||||
[_ (int-err "update on mutable struct field")]))
|
||||
proc poly pred)]
|
||||
(let/ec abort
|
||||
(make-Struct nm par
|
||||
(list-update flds idx (match-lambda
|
||||
[(fld: e acc-id #f)
|
||||
(let ([ft* (update e ft pos? rst)])
|
||||
(if (Bottom? ft*)
|
||||
(abort ft*)
|
||||
(make-fld ft* acc-id #f)))]
|
||||
[_ (int-err "update on mutable struct field")]))
|
||||
proc poly pred))]
|
||||
|
||||
;; otherwise
|
||||
[(t '())
|
||||
|
|
17
typed-racket-test/succeed/struct-update.rkt
Normal file
17
typed-racket-test/succeed/struct-update.rkt
Normal file
|
@ -0,0 +1,17 @@
|
|||
#lang typed/racket/base
|
||||
|
||||
;; ensures updates to a struct's field
|
||||
;; which results in Bottom
|
||||
;; properly propogates Bottom up
|
||||
|
||||
(define-type ABC (U 'a 'b 'c))
|
||||
|
||||
(define-struct ABCWrapper ([abc : ABC]))
|
||||
|
||||
(: abc-123-let (ABCWrapper -> (U 1 2 3)))
|
||||
(define (abc-123-let wrapper)
|
||||
(let ([abc (ABCWrapper-abc wrapper)])
|
||||
(cond
|
||||
[(eq? abc 'a) 1]
|
||||
[(eq? abc 'b) 2]
|
||||
[(eq? abc 'c) 3])))
|
Loading…
Reference in New Issue
Block a user