racket/collects/tests/generic/errors.rkt
Claire Alvis d84494dd44 Fixes strange error messages for invalid generic method definitions
Closes PR 13681

Please merge to v5.3.4
2013-04-12 16:10:27 -04:00

44 lines
1.8 KiB
Racket

#lang racket/base
(require racket/generic unstable/macro-testing)
(module+ test
(require rackunit)
(check-exn #rx"not a name for a generics group"
(lambda () (convert-compile-time-error
(struct foo () #:methods 3))))
(check-exn #rx"not a name for a generics group"
(lambda () (convert-compile-time-error
(struct foo () #:methods bad))))
(check-exn #rx"method definition has an incorrect arity"
(lambda () (convert-compile-time-error
(let ()
(define-generics foobar
[foo foobar x])
(struct inst ()
#:methods gen:foobar
[(define (foo) 0)])
'ignore))))
(check-exn #rx"method definition has an incorrect arity"
(lambda () (convert-compile-time-error
(let ()
(define-generics foobar
[foo foobar x]
[bar foobar x])
(struct inst ()
#:methods gen:foobar
[(define (foo foobar x) 0)
(define (bar foobar) 1)])
'ignore))))
(check-exn #rx"generic method definition is not a function"
(lambda () (convert-compile-time-error
(let ()
(define-generics foobar
[foo foobar x])
(struct inst ()
#:methods gen:foobar
[(define foo 0)])
'ignore))))
)