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 cf8825cf..e76639c6 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 @@ -1054,7 +1054,9 @@ (for/or ([m (in-set required)]) (and (not (set-member? actual m)) m))) (when missing - (tc-error/expr "class definition missing ~a ~a" msg missing))) + (tc-error/expr (~a "class definition missing ~a ~a " + "that is required by the expected type") + msg missing))) ;; Set Set String -> Void ;; check that names are absent when they should be @@ -1073,22 +1075,17 @@ (for/or ([m (in-set expected)]) (and (not (set-member? actual m)) m))) (when missing - (tc-error/expr "class definition missing ~a ~a" msg missing)) + (tc-error/expr (~a "class definition missing ~a ~a " + "that is required by the expected type") + msg missing)) (define too-many (for/or ([m (in-set actual)]) (and (not (set-member? expected m)) m))) (when too-many - (tc-error/expr "class definition has unexpected ~a ~a" + (tc-error/expr (~a "class definition contains ~a ~a " + "that is not in the expected type") msg too-many))) -;; check-no-extra : Set Set -> Void -;; check that the actual names don't include names not in the -;; expected type (i.e., the names must exactly match up) -(define (check-no-extra actual expected) - (unless (subset? actual expected) - ;; FIXME: better error reporting here - (tc-error/expr "class defines names not in expected type"))) - ;; I wish I could write this #; (module+ test 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 c7a7cf20..15d129cd 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 @@ -179,21 +179,24 @@ (define n% (class j% (super-new)))) ;; should fail, too many methods - (check-err #:exn #rx"unexpected public method m" + (check-err + #:exn #rx"public method m that is not in the expected type" (: o% (Class)) (define o% (class object% (super-new) (define/public (m) 0)))) ;; same as previous - (check-err #:exn #rx"unexpected public method n" + (check-err + #:exn #rx"public method n that is not in the expected type" (: c% (Class [m (Integer -> Integer)])) (define c% (class object% (super-new) (define/public (m x) (add1 x)) (define/public (n) 0)))) ;; fails, too many inits - (check-err #:exn #rx"unexpected initialization argument x" + (check-err + #:exn #rx"initialization argument x that is not in the expected type" (: c% (Class)) (define c% (class object% (super-new) (init x)))) @@ -205,7 +208,8 @@ (init str)))) ;; fails, too many fields - (check-err #:exn #rx"unexpected public field x" + (check-err + #:exn #rx"public field x that is not in the expected type" (: c% (Class (field [str String]))) (define c% (class object% (super-new) (field [str "foo"] [x 0])))) @@ -485,7 +489,8 @@ (define d% (class c% (super-new)))) ;; fails, expected mandatory but got optional - (check-err #:exn #rx"unexpected optional init argument x" + (check-err + #:exn #rx"optional init argument x that is not in the expected type" (: c% (Class (init [x Integer]))) (define c% (class object% (super-new) (: x Integer)