Improve types for private field accessors
Enables better occurrence typing for private fields
This commit is contained in:
parent
5b237018ef
commit
78fc0f19e7
|
@ -854,15 +854,14 @@
|
|||
[getter-id (in-list getter-ids)])
|
||||
(define maybe-type (dict-ref type-map field-name #f))
|
||||
(values
|
||||
(make-Function
|
||||
;; This case is more complicated than for public fields because private
|
||||
;; fields support occurrence typing. The object is set as the field's
|
||||
;; accessor id, so that *its* range type is refined for occurrence typing.
|
||||
(list (make-arr* (list Univ)
|
||||
(or (and maybe-type (car maybe-type))
|
||||
Univ)
|
||||
#:object
|
||||
(make-Path (list (make-FieldPE)) getter-id))))
|
||||
;; This case is more complicated than for public fields because private
|
||||
;; fields support occurrence typing. The object is set as the field's
|
||||
;; accessor id, so that *its* range type is refined for occurrence typing.
|
||||
(->acc (list Univ)
|
||||
(or (and maybe-type (car maybe-type))
|
||||
Univ)
|
||||
(list (make-FieldPE))
|
||||
#:var getter-id)
|
||||
(-> Univ (or (and maybe-type (car maybe-type)) -Bottom)
|
||||
-Void))))
|
||||
|
||||
|
|
|
@ -1945,6 +1945,18 @@
|
|||
(if (string? x) (string-append x "bar") "baz"))))
|
||||
(send (new c%) m))
|
||||
-String]
|
||||
[tc-e (let ()
|
||||
(define c%
|
||||
(class object%
|
||||
(super-new)
|
||||
(: x (U String #f))
|
||||
(define x "foo")
|
||||
(: m (-> String))
|
||||
(define/public (m)
|
||||
;; ensure just x works
|
||||
(if x (string-append x "bar") "baz"))))
|
||||
(send (new c%) m))
|
||||
-String]
|
||||
[tc-e (let ()
|
||||
(define c%
|
||||
(class object%
|
||||
|
@ -1965,6 +1977,12 @@
|
|||
;; let-aliasing + occ. typing on fields
|
||||
(let ([y x]) (if (string? y) (string-append x) "")))
|
||||
(-class)]
|
||||
[tc-e (class object%
|
||||
(super-new)
|
||||
(: x (Option String))
|
||||
(define x "foo")
|
||||
(let ([y x]) (if y (string-append x) "")))
|
||||
(-class)]
|
||||
;; Failure tests for occurrence typing on private fields. The types
|
||||
;; are obfuscated a bit to prevent interference from type aliases in
|
||||
;; another test.
|
||||
|
|
Loading…
Reference in New Issue
Block a user