expander: improve error reporting for definitions without expression

Closes #2183
This commit is contained in:
Matthew Flatt 2018-08-18 09:07:56 -06:00
parent 369eb65ec2
commit a01feffa83
3 changed files with 313 additions and 293 deletions

View File

@ -868,6 +868,15 @@
(test 5 'implicit-begin (let () (begin) 10 5))
;; Check that expansion-introduced `let-values` is not mentioned in
;; the error message
(define (exn:begin-possibly-implicit? x)
(and (exn? x)
(regexp-match? #rx"begin .possibly implicit." (exn-message x))))
(error-test #'(let () (define x 0)) exn:begin-possibly-implicit?)
(error-test #'(let () (struct a ())) exn:begin-possibly-implicit?)
(error-test #'(cond [#t (define x 0)]) exn:begin-possibly-implicit?)
;; Weird test: check that `eval` does not wrap its last argument
;; in a prompt, which means that `(foo 10)` replaces the continuation
;; that would check for an error

View File

@ -85,6 +85,7 @@
(finish-expanding-body body-ctx frame-id def-ctx-scopes
(reverse val-idss) (reverse val-keyss) (reverse val-rhss) (reverse track-stxs)
(reverse stx-clauses) (reverse done-bodys)
#:original-bodys init-bodys
#:source s
#:stratified? stratified?
#:name name
@ -228,12 +229,15 @@
(define (finish-expanding-body body-ctx frame-id def-ctx-scopes
val-idss val-keyss val-rhss track-stxs
stx-clauses done-bodys
#:original-bodys init-bodys
#:source s
#:stratified? stratified?
#:name name
#:disappeared-transformer-bindings disappeared-transformer-bindings)
(when (null? done-bodys)
(raise-syntax-error #f "no expression after a sequence of internal definitions" s))
(raise-syntax-error (string->symbol "begin (possibly implicit)")
"no expression after a sequence of internal definitions"
(datum->syntax #f (cons 'begin init-bodys) s)))
;; As we finish expanding, we're no longer in a definition context
(define finish-ctx (struct*-copy expand-context (accumulate-def-ctx-scopes body-ctx def-ctx-scopes)
[context 'expression]

File diff suppressed because it is too large Load Diff