Add support for basic polymorphic classes
original commit: 91729c060cd431cb3b438aa6f0d3572ed456ab22
This commit is contained in:
parent
f59585bb5a
commit
4947ef6e53
|
@ -161,6 +161,8 @@
|
|||
(match (and expected (resolve expected))
|
||||
[(tc-result1: (and self-class-type (Class: _ _ _ _ _)))
|
||||
(do-check form #t self-class-type)]
|
||||
[(tc-result1: (Poly-names: ns body-type))
|
||||
(check-class form (ret body-type))]
|
||||
[#f (do-check form #f #f)]
|
||||
[_ (check-below (do-check form #f #f) expected)]))
|
||||
|
||||
|
|
|
@ -973,5 +973,23 @@
|
|||
(class: object%
|
||||
(super-new)
|
||||
(: x Integer)
|
||||
(init-field x))))))
|
||||
(init-field x))))
|
||||
|
||||
;; test polymorphic class
|
||||
(check-ok
|
||||
(: c% (All (A) (Class (init-field [x A]))))
|
||||
(define c%
|
||||
(class: object%
|
||||
(super-new)
|
||||
(init-field x)))
|
||||
(new (inst c% Integer) [x 0]))
|
||||
|
||||
;; fails due to ill-typed polymorphic class body
|
||||
(check-err #:exn #rx"Expected A, but got Positive-Byte"
|
||||
(: c% (All (A) (Class (init-field [x A]))))
|
||||
(define c%
|
||||
(class: object%
|
||||
(super-new)
|
||||
(init-field x)
|
||||
(set! x 5))))))
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user