diff --git a/collects/mzlib/kw.ss b/collects/mzlib/kw.ss index f8830e3931..44547d49d0 100644 --- a/collects/mzlib/kw.ss +++ b/collects/mzlib/kw.ss @@ -40,8 +40,17 @@ ;; turns formals into a syntax list (define (formals->list formals) (syntax-case formals () - [(formal ... . rest) ; dot is exactly like #:rest - (formals->list #'(formal ... #:rest rest))] + [(formal ... . rest) + ;; dot is exactly like #:rest, but don't allow it with other + ;; meta-keywords since its meaning is confusing + (let* ([formals (syntax->list #'(formal ...))] + [kwd (ormap (lambda (s) (and (keyword? (syntax-e* s)) s)) + formals)]) + (if kwd + (serror #'rest "use #:rest or #:body instead of dot notation" + ;; (syntax-e* kwd) <- confusing to show this + ) + (append formals (list #'#:rest #'rest))))] [(formal ...) (syntax->list formals)])) ;; is an expression simple? (=> evaluating cannot have side effects) (define (simple-expr? expr) @@ -111,9 +120,9 @@ ([(only-vars?) (and (pair? only-vars?) (car only-vars?))] [(opts keys0) (values (map process-opt opts) (map process-key keys0))] [(rest body rest-keys all-keys other-keys) - (apply values - (map (lambda (k) (cond [(assq k rests) => cdr] [else #f])) - '(#:rest #:body #:rest-keys #:all-keys #:other-keys)))] + (apply values (map (lambda (k) + (cond [(assq k rests) => cdr] [else #f])) + rest-like-kwds))] [(rest* body* other-keys*) (values (or rest (gensym #'rest)) (if (and body (identifier? body)) body (gensym #'body)) diff --git a/collects/tests/mzscheme/kw.ss b/collects/tests/mzscheme/kw.ss index 1a4309d70f..8a1b618d39 100644 --- a/collects/tests/mzscheme/kw.ss +++ b/collects/tests/mzscheme/kw.ss @@ -288,6 +288,7 @@ ;; test syntax errors (t :st-err: <= (lambda/kw (x #:blah y) 1) :st-err: <= (lambda/kw (x #:rest) 1) + :st-err: <= (lambda/kw (x #:key k . r) 1) :st-err: <= (lambda/kw (x #:key k #:key o) 1) :st-err: <= (lambda/kw (x #:key k #:optional o) 1) :st-err: <= (lambda/kw (x #:optional k #:optional o) 1)