diff --git a/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/typecheck/tc-send.rkt b/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/typecheck/tc-send.rkt index f4cee81a..f0b5beab 100644 --- a/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/typecheck/tc-send.rkt +++ b/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/typecheck/tc-send.rkt @@ -16,15 +16,21 @@ (match rcvr-type [(tc-result1: (Instance: (? needs-resolving? type))) (do-check (ret (make-Instance (resolve type))))] - [(tc-result1: (Instance: (and c (Class: _ _ _ methods _ _)))) + [(tc-result1: (and obj (Instance: (Class: _ _ _ methods _ _)))) (match (tc-expr method) [(tc-result1: (Value: (? symbol? s))) (let* ([ftype (cond [(assq s methods) => cadr] - [else (tc-error/expr "send: method ~a not understood by class ~a" s c)])] + [else (tc-error/expr/fields "send: method not understood by object" + "method name" s + "object type" obj)])] [retval (tc/funapp rcvr args (ret ftype) (stx-map tc-expr args) expected)]) (add-typeof-expr form retval) retval)] [(tc-result1: t) (int-err "non-symbol methods not supported by Typed Racket: ~a" t)])] - [(tc-result1: t) (tc-error/expr #:return (or expected (ret -Bottom)) "send: expected a class instance, got ~a" t)])) + [(tc-result1: t) (tc-error/expr/fields + #:return (or expected (ret -Bottom)) + "send: type mismatch" + "expected" "an object" + "given" t)])) (do-check (tc-expr rcvr))) 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 6b50c7ab..3ab96746 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 @@ -75,7 +75,7 @@ (init [x 0]) (define/public (m x) (send this z)))) (void)) - #:msg #rx"method z not understood"] + #:msg #rx"method not understood.*method name: z"] ;; Send to other methods [tc-e (let () (: h% (Class [n (-> Integer)]