From ad4f6e1ea1f9c0e2e7ca30e6ea6d8c6e8a50f0ca Mon Sep 17 00:00:00 2001 From: Asumu Takikawa Date: Mon, 10 Feb 2014 17:32:53 -0500 Subject: [PATCH] Better error messages for TR lambda parsing --- .../typed-racket/base-env/prims.rkt | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/base-env/prims.rkt b/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/base-env/prims.rkt index c0ba61f476..6d451fe866 100644 --- a/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/base-env/prims.rkt +++ b/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/base-env/prims.rkt @@ -1183,21 +1183,28 @@ This file defines two sorts of primitives. All of them are provided into any mod #:attr opt-property (list (length (attribute mand)) (length (attribute opt))) #:attr erased - (template ((?@ . mand.form) ... (?@ . opt.form) ... . rest.form))))) + (template ((?@ . mand.form) ... (?@ . opt.form) ... . rest.form)))) + + (define-splicing-syntax-class return-ann + #:description "return type annotation" + #:literals (:) + (pattern (~seq : type:expr)) + (pattern (~seq) #:attr type #f))) ;; annotation to help tc-expr pick out keyword functions (define-syntax (-lambda stx) (syntax-parse stx #:literals (:) - [(_ formals:lambda-formals (~optional (~seq : return-type:expr)) - e ... last-e) + [(_ formals:lambda-formals return:return-ann + (~describe "body expression or definition" e) ... + (~describe "body expression" last-e)) ;; Annotate the last expression with the return type. Should be correct ;; since if a function returns, it has to do so through the last expression ;; even with continuations. (define/with-syntax last-e* - (if (attribute return-type) - #`(ann last-e #,(attribute return-type)) + (if (attribute return.type) + #`(ann last-e #,(attribute return.type)) #'last-e)) (define d (syntax/loc stx (λ formals.erased e ... last-e*))) (if (attribute formals.kw-property)