diff --git a/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/typecheck/tc-app/tc-app-objects.rkt b/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/typecheck/tc-app/tc-app-objects.rkt index 0859164f08..a608052229 100644 --- a/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/typecheck/tc-app/tc-app-objects.rkt +++ b/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/typecheck/tc-app/tc-app-objects.rkt @@ -60,8 +60,10 @@ [(and c (Class: _ inits fields _ _ init-rest)) (cond [;; too many positional arguments, fail (and (> (length pos-args) (length inits)) (not init-rest)) - ;; FIXME: better message - (tc-error "too many positional arguments supplied")] + (tc-error/fields "failure in class instantiation" + #:more "too many positional arguments supplied" + "expected" (format "~a arguments" (length inits)) + "given" (format "~a arguments" (length pos-args)))] [;; more args than inits, now feed them to init-rest (and (> (length pos-args) (length inits))) (define-values (pos-for-inits other-pos) @@ -80,8 +82,12 @@ (tc-expr/check pos-arg (ret type))) (check-named-inits other-inits given-names name-assoc)]) (ret (make-Instance c))] + [(ClassTop:) (tc-error/expr/fields "failure in class instantiation" + #:more "cannot instantiate a value of type ClassTop")] [t - (tc-error/expr "expected a class value for object creation, got: ~a" t)])) + (tc-error/expr/fields "failure in class instantiation" + #:more "given a value of a non-class type" + "given" t)])) (define (check-named-inits inits names name-assoc) (define init-names (map car inits)) 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 4eb8c5eaa9..6144489351 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 @@ -1420,4 +1420,11 @@ (define/public (m arg ...) . body)) (my-meth (hello) (displayln "hello world")))) (send (new c%) hello)) - -Void])) + -Void] + ;; the next few tests check failing class instantiation + [tc-err (make-object object% 1) + #:msg #rx"expected: 0 arguments.*given: 1 arguments"] + [tc-err (make-object (ann object% ClassTop)) + #:msg #rx"cannot instantiate.*ClassTop"] + [tc-err (make-object 3) + #:msg #rx"value of a non-class type"]))