Improve handling of expected type
original commit: 71d590604f33ecf9e9f2fb31307b4b01f79fc048
This commit is contained in:
parent
6bd6b9e1e2
commit
f59585bb5a
|
@ -18,7 +18,7 @@
|
|||
(base-env class-prims)
|
||||
(env lexical-env)
|
||||
(types utils abbrev union subtype resolve)
|
||||
(typecheck internal-forms)
|
||||
(typecheck check-below internal-forms)
|
||||
(utils tc-utils)
|
||||
(rep type-rep)
|
||||
(for-template racket/base
|
||||
|
@ -158,12 +158,11 @@
|
|||
;; we know by this point that #'form is an actual typed
|
||||
;; class produced by class: due to the syntax property
|
||||
(define (check-class form [expected #f])
|
||||
(match expected
|
||||
[(tc-result1: (? Mu? type))
|
||||
(check-class form (ret (unfold type)))]
|
||||
(match (and expected (resolve expected))
|
||||
[(tc-result1: (and self-class-type (Class: _ _ _ _ _)))
|
||||
(do-check form #t self-class-type)]
|
||||
[#f (do-check form #f #f)]))
|
||||
[#f (do-check form #f #f)]
|
||||
[_ (check-below (do-check form #f #f) expected)]))
|
||||
|
||||
;; Syntax Boolean Option<Type> -> Type
|
||||
;; Do the actual type-checking
|
||||
|
|
|
@ -964,5 +964,14 @@
|
|||
(class: object%
|
||||
(super-new)
|
||||
(define/pubment (m x) 0)))
|
||||
(send (new c%) m 3))))
|
||||
(send (new c%) m 3))
|
||||
|
||||
;; fails, expected type not a class
|
||||
(check-err #:exn #rx"Expected Number"
|
||||
(: c% Number)
|
||||
(define c%
|
||||
(class: object%
|
||||
(super-new)
|
||||
(: x Integer)
|
||||
(init-field x))))))
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user