Improve error messages

original commit: 37c313e9b3f4c1cebc726711616b4ec4fcef747d
This commit is contained in:
Asumu Takikawa 2013-08-01 17:14:03 -04:00
parent ea7d2b92cd
commit 707f6ed62d
2 changed files with 18 additions and 16 deletions

View File

@ -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<Symbol> Set<Symbol> 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<Symbol> Set<Symbol> -> 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

View File

@ -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)