Improve error messages
This commit is contained in:
parent
27a7322033
commit
37c313e9b3
|
@ -1054,7 +1054,9 @@
|
||||||
(for/or ([m (in-set required)])
|
(for/or ([m (in-set required)])
|
||||||
(and (not (set-member? actual m)) m)))
|
(and (not (set-member? actual m)) m)))
|
||||||
(when missing
|
(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
|
;; Set<Symbol> Set<Symbol> String -> Void
|
||||||
;; check that names are absent when they should be
|
;; check that names are absent when they should be
|
||||||
|
@ -1073,22 +1075,17 @@
|
||||||
(for/or ([m (in-set expected)])
|
(for/or ([m (in-set expected)])
|
||||||
(and (not (set-member? actual m)) m)))
|
(and (not (set-member? actual m)) m)))
|
||||||
(when missing
|
(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
|
(define too-many
|
||||||
(for/or ([m (in-set actual)])
|
(for/or ([m (in-set actual)])
|
||||||
(and (not (set-member? expected m)) m)))
|
(and (not (set-member? expected m)) m)))
|
||||||
(when too-many
|
(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)))
|
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
|
;; I wish I could write this
|
||||||
#;
|
#;
|
||||||
(module+ test
|
(module+ test
|
||||||
|
|
|
@ -179,21 +179,24 @@
|
||||||
(define n% (class j% (super-new))))
|
(define n% (class j% (super-new))))
|
||||||
|
|
||||||
;; should fail, too many methods
|
;; 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))
|
(: o% (Class))
|
||||||
(define o% (class object%
|
(define o% (class object%
|
||||||
(super-new)
|
(super-new)
|
||||||
(define/public (m) 0))))
|
(define/public (m) 0))))
|
||||||
|
|
||||||
;; same as previous
|
;; 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)]))
|
(: c% (Class [m (Integer -> Integer)]))
|
||||||
(define c% (class object% (super-new)
|
(define c% (class object% (super-new)
|
||||||
(define/public (m x) (add1 x))
|
(define/public (m x) (add1 x))
|
||||||
(define/public (n) 0))))
|
(define/public (n) 0))))
|
||||||
|
|
||||||
;; fails, too many inits
|
;; 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))
|
(: c% (Class))
|
||||||
(define c% (class object% (super-new)
|
(define c% (class object% (super-new)
|
||||||
(init x))))
|
(init x))))
|
||||||
|
@ -205,7 +208,8 @@
|
||||||
(init str))))
|
(init str))))
|
||||||
|
|
||||||
;; fails, too many fields
|
;; 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])))
|
(: c% (Class (field [str String])))
|
||||||
(define c% (class object% (super-new)
|
(define c% (class object% (super-new)
|
||||||
(field [str "foo"] [x 0]))))
|
(field [str "foo"] [x 0]))))
|
||||||
|
@ -485,7 +489,8 @@
|
||||||
(define d% (class c% (super-new))))
|
(define d% (class c% (super-new))))
|
||||||
|
|
||||||
;; fails, expected mandatory but got optional
|
;; 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])))
|
(: c% (Class (init [x Integer])))
|
||||||
(define c% (class object% (super-new)
|
(define c% (class object% (super-new)
|
||||||
(: x Integer)
|
(: x Integer)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user