From f59585bb5a0f46ed14ba38f01367a81912827f61 Mon Sep 17 00:00:00 2001 From: Asumu Takikawa Date: Thu, 11 Jul 2013 16:00:40 -0400 Subject: [PATCH] Improve handling of expected type original commit: 71d590604f33ecf9e9f2fb31307b4b01f79fc048 --- .../typed-racket/typecheck/check-class-unit.rkt | 9 ++++----- .../tests/typed-racket/unit-tests/class-tests.rkt | 11 ++++++++++- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/typecheck/check-class-unit.rkt b/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/typecheck/check-class-unit.rkt index f1833752..db98767e 100644 --- a/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/typecheck/check-class-unit.rkt +++ b/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/typecheck/check-class-unit.rkt @@ -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 ;; Do the actual type-checking diff --git a/pkgs/typed-racket-pkgs/typed-racket-test/tests/typed-racket/unit-tests/class-tests.rkt b/pkgs/typed-racket-pkgs/typed-racket-test/tests/typed-racket/unit-tests/class-tests.rkt index 2302212c..b5e5a3fa 100644 --- a/pkgs/typed-racket-pkgs/typed-racket-test/tests/typed-racket/unit-tests/class-tests.rkt +++ b/pkgs/typed-racket-pkgs/typed-racket-test/tests/typed-racket/unit-tests/class-tests.rkt @@ -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))))))