fixed struct field updates

This commit is contained in:
Andrew Kent 2015-01-14 15:32:34 +05:30
parent e922807837
commit e7d61bd982
2 changed files with 27 additions and 6 deletions

View File

@ -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 '())

View 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])))