Check that => is followed by an identifier in match clauses.

Closes #2830.
This commit is contained in:
Sam Tobin-Hochstadt 2019-09-24 12:36:34 -04:00 committed by Sam Tobin-Hochstadt
parent 00969092c8
commit 920d3ce51e
2 changed files with 9 additions and 1 deletions

View File

@ -515,6 +515,10 @@
(comp 'yes (with-handlers ([exn:fail:syntax? (lambda _ 'yes)]) (expand #'(match-lambda ((a ?) #f))) 'no))
(comp 'yes (with-handlers ([exn:fail:syntax? (lambda _ 'yes)]) (expand #'(match-lambda ((?) #f))) 'no))
(comp 'yes (with-handlers ([exn:fail:syntax? (lambda _ 'yes)]
[exn:fail? (lambda _ 'no)])
(expand #'(match 1 [1 (=> (fail)) 1]))
'no))
(comp
'yes

View File

@ -69,7 +69,11 @@
"expected at least one expression on the right-hand side after #:when clause"
clause)]
[(#:when e rest ...) (mk #f #'((if e (let () rest ...) (fail))))]
[(((~datum =>) unm) . rhs) (mk #'unm #'rhs)]
[(((~datum =>) unm:id) . rhs) (mk #'unm #'rhs)]
[(((~datum =>) unm) . rhs)
(raise-syntax-error 'match
"expected an identifier after `=>`"
#'unm)]
[_ (mk #f rhs)])))
(define/with-syntax body
(compile* (syntax->list #'(xs ...)) parsed-clauses #'outer-fail))